I have a bitmap font sheet, and I would like to have each glyph as its own separate image. Do I just need to manually find the width of each glyph and extract them one by one, or is there a better way to do it?
If you're only going to do it once, a quick and simple way is to just display each character in a window and do a screen capture, then split that image into pieces. If you use something that recognizes Tab characters you can get them evenly spaced so that you don't have to measure more than one character.
Related
I am using the black and white circle in my project when I noticed that on ios chrome the white circle is larger than the black circle.
● - U+25CF
○ - U+25CB
In a desktop environment the circles appear to be the same size but have slightly different heights. The difference is not noticeable.
I am trying to make these circles the same size on ios chrome.
I feel like I have eliminated any variables and that the browser is responsible for the different sizes of these circles.
photo
Actually, as far as unicode is concerned, all characters are font dependant. When a certain character is not available, it is picked from a fallback font.
If you had not configured a custom font, or if these chars are not available in the font you picked then the different sized circles are in the default font used by chrome/ios.
So, you have two ways to go: either find a font that have the characters drawn in a way that suits you, and force that, or give-up using unicode characters for these glyphs and use inline images instead.
You could make use of SVG drawings which can be encoded within the HTML markup itself, that will ensure a consistent look.
I'm at my whits end... trying to get a custom list of pictures, a TImageList and a TListView to work together. Original problem: No dynamically-added pictures are displayed in the list. Narrowed it down, problem is in the TImagelist. Code is below. ilMain is the TImagelist (defined elsewhere). Adding a bitmap to the list, immediatly retrieving it, first "Draw" works fine but the sedond fails... what am I missing here?
var i:integer;
test:TSch;
currentimage :TBitmap;
stupid :TBitmap;
begin
currentImage:=TBitmap.Create;
stupid:=TBitmap.Create;
ilMain.Clear;
// currentImage.LoadFromFile('C:\Delphi\piccat\pics\MonaLisa.jpg');
JPeg2Bmp('C:\Delphi\piccat\pics\MonaLisa.jpg',currentImage);
form1.canvas.Draw(100,10,currentimage);
ilMain.Add(currentimage,nil);
ilMain.GetBitmap(0,stupid);
form1.canvas.Draw(200,10,stupid);
EDIT:
Done some further testing on this one; results are very confusing and inconsistent.
Result are actually GREATLY dependant on the size of the input file (thanks for that pointer, kobik!); it seems everything smaller than 256x256 isn't imported into the imagelist, while bigger pictures ALONG THE X-AXIS are (sometimes??) spread over several items.
ilMain was set to 256x256 pixels.
Here is the output for several input sizes (X x Y, in pixels):
950x414
First draw displays entire image, second take 256x256 pixels in the upper left corner. HOWEVER, THREE items of the TImagelist are populated, with 3x 256x256 pixels: the three pictures that can be "cut out" from the main picture and still be 256x256 pixels. All edges cut off which are smaller, either vertical or horizontal, than 256x256 are lost.
1600x1600
Six images are imported; the first row of complete 256x256 blocks which can be cut from the top of the pic. The incomplete block on the tp right is omitted, and all rows below Y-size 256 as well.
1500x1000
Similar to previous one; five items imported now.
638x376
Again similar; only two items "fit" now.
197x256 (my original test file, described in post above)
NO ITEMS IMPORTED (X-size is smaller than TImaglist X-size?)
256x256
AGAIN, NO DATA IMPORTED
257x257
STILL NO DATA IMPORTED
260x260
STILL NO DATA IMPORTED
300x300
STILL NO DATA IMPORTED
512x256
Very weird one. One pic is imported; BUT it is reduced in size, so approximately 70% of the original pic fits in the (new) 256 X size. A black bar is added below the pic to make up for the lost space due to this shrinking.
So this is where I stop testing for now, and wondering if anyone can shed some light here...?
EDIT: Design part moved to new question (see request in comment kobik, thanks man!)
Your code works (or at-least needs to work) assuming your JPeg2Bmp is correct. I guess #Dima's second comment is correct.
You haven't showed the ilMain properties, and if you use the default you get an imagelist with Width/Height=16.
Try to omit the first call to form1.canvas.Draw(100,10,currentimage);, and draw only the form1.canvas.Draw(200,10,stupid); and You should see a 16x16 drawing at position 200,10.
TImagelist can't load arbitrary image sizes.
You need to pre-define it's size, and load the bitmaps with suitable sizes. i.e. create thumbnails to fit the imagelist dimensions.
Note also that (you probably know that) You need to draw only in response to WM_PAINT Message. e.g. in the Form OnPaint event.
EDIT: As regard to your edit, this is how TImageList works. if you add a bitmap that is larger than the imagelist width, it will attempt to break the bitmap into separate bitmaps to fit the imagelist size. this is by design.
See the documentation about ImageList_Add about the hbmImage parameter:
A handle to the bitmap that contains the image or images. The number
of images is inferred from the width of the bitmap.
I’m new in iOS and trying to make simple app with hierarchy of viewcontrollers. In the last one I wanna display scrollable image (which can also be zoomed at least x1,5), containing some small black and white picture and a piece of text. Initially I planned to make vector image, convert it to .jpg and use UIScrollView for displaying. But I found out that .jpg ( approx. 150 KB) didn’t provide a good quality for displaying text. As I have to use a lot of images I don’t want to increase image size. What is worse I also want it look good on retina display.
Can you recommend a way how to display image, containing text, with enough quality?
I mean that I don’t want the user see the separate pixels of letters in the text. Just like when you read text in your e-mail in iOS. Image size should be as small as possible. Planning physical size of image – approx. 5 cm x 15 cm.
Any help much appreciated
Thanks
To get good edges you would need to use png not jpg, which will make the image sizes much larger. I have a better suggestion, more code but better solution.
The answer is to not put the text into the image, but to draw it over it in real time.
You would:
associate text at some coordinate in the image (say a CGRect) with the image
create a uiimageview subclass that in the drawRect routine, after calling super, draws the text using the NSString categories on UIKit (which let you draw into a context)
To get going on this please create a small one vc project and get the subclass working there, then back port it to your primary project.
I am wondering if it is possible to add small icons, that are available as png files, during launch time to a custom font I use in my app? The code should work on iOS5 and above. This would have several use cases. For example you could add labels with icons without using an image view and a label and layouting the stuff based on the text. I know that I have read somewhere, that apple uses this technique on their own apps, but I don't know if they add the icons on launch time or already in the design process into the font.
Any help would be appreciated.
I have simulated this by using a custom view that has a string and font property as well as one or more images. Create a mapping between special char values and images. In drawrect use the uikit category on NSString that lets you draw chars or strings. When u get to your special char you skip it and draw the image. Those draw methods return the size of the string/char so you can tell how much to move as you draw.
You can see this technique used on github, look for the CreditCard ObjectiveC. It's used to draw placeholders or chars in the PlaceHolder class
I think it is not possible to add png to font in device. Font file use vector graphics to represent every glyph. You can convert font file to SVG. But PNG is not vector graphics.
I use icon font in some of my projects. I have create a project to use icon font easily. https://github.com/JohnWong/IconFont. Icon font is always used in UILabel by setting text. But I think creating a UIImage from font is more flexible. UIImage can be used in Buttons, TabBar Items, Bar Button Items and so on. This is why I create this project. The README of this project is written in Chinese. But the demo project will show everything clearly.
I used the 9330 simulator for developing my app, and now once I put it on a blackberry bold, I've noticed that my text and images appear much smaller on the device than the simulator. Is there anyway to fix this without having to change every objects height and width? Maybe I need to use Display.getHeight() and .getWidth() more instead of hardcoding numbers?
One way I dealt with this is making the size of my elements variable. I did this by, upon loading the app, detecting the screen size and applying a multiplier that modifies my elements by a given %, the % depends on the screen size. I calculated these percentages by taking a base screen size and seeing how much the screen sized varied from one model to another, there are only 4 screen sizes I believe.
Yes, you shouldn't hardcode any number as bold and curve have differnt screen resolutions
Curve: 8800s, 8300s, 8500s, 9300s 320x240
Bold: 8900s, 9000s, 9600s, 9700s 480x360, 480x320 (Bold 9000)
You will have to change every place you used that numbers and change to gethHeight and getWidth() where needed
For the images you should scale the object, something like this:
Bitmap bitmap = new Bitmap(width, height);
yourBitmap.scaleInto(bitmap, Bitmap.FILTER_BILINEAR);
For texts you should use something like this:
LabelField field = new LabelField("TEST");
field.setFont(field.getFont().derive(Font.PLAIN, yourFontSize));