Is iOSBitmap working as intended?

I’ve been trying to use iOSBitmap in an app and its quirks have surprised me. According to the docs, you must supply the screen scale and multiply both the height and width by the scale factor. Unfortunately, multiplying the height and width by the scale makes no difference when the bitmap is converted to an image and drawn into a graphics object. Some very simple code which should produce the same result but does not:
In a canvas paint event:

g.FillColor = g.FillRect 0,0,g.Width,g.Height g.FillColor = g.DrawTextLine "This is a canvas", 10, g.Height/2

In another canvas paint event:

[code] dim bitmap as new iOSBitmap(g.WidthScreenScale, g.HeightScreenScale, ScreenScale)
dim g2 as iOSGraphics = bitmap.Graphics
g2.FillColor =
g2.FillRect 0,0,g.Width,g.Height
g2.FillColor =
g2.DrawTextLine “This is a canvas”, 10, g.Height/2

g.DrawImage bitmap.Image, 0, 0[/code]

A function you will need:

[code]Function ScreenScale() As Double
'[[UIScreen mainScreen] scale]
declare function mainScreen lib UIKitLib selector “mainScreen” (clsRef as ptr) as ptr
#if Target32Bit
declare function scale Lib UIKitLib selector “scale” (obj_id as ptr) as Single
#elseif Target64Bit
declare function scale Lib UIKitLib selector “scale” (obj_id as ptr) as Double

Return scale(mainScreen(NSClassFromString(“UIScreen”)))
End Function[/code]

Am I somehow missing something in iOSBitmap, or does it not work as intended with scales greater than 1? Using a scale of one in the above code makes the drawing the correct dimensions, but everything is blurry because the screen has a scale of 2.

I would appreciate any insight or work arounds to make this work correctly for scales greater than 1.

Jason I’m no expert at graphics functions, but a quick check of my code shows that where you do this:

dim bitmap as new iOSBitmap(g.Width*ScreenScale, g.Height*ScreenScale, ScreenScale)

I do this:

dim bitmap as new iOSBitmap(g.Width, g.Height, ScreenScale)

In other words, I don’t multiple the size of the bitmap by the scale.

Hi Jason,
Thanks for the reply. I just tried to change my code to mirror yours, and don’t see a difference between the new and old whatsoever which doesn’t seem right. I really think I must be missing something or there is a significant bug present.

Also in my app, where you have:

g2.FillRect 0,0,g.Width,g.Height

I have

g2.FillRect 0,0,g.Width * ScreenScale,g.Height * ScreenScale

There might be something missing in the docs. I added retina-compatible graphics to my app right at the start and I seem to remember having to play around with a few things to get it right due to a lack of examples. I think this was one of those things.

Well that solves half of the problem, thanks :). The blue background is now drawn correctly, however the Text is still drawn very small. I’ll have to keep trying different combinations.

Try multiplying the size of the text by the scale as well. That’s what I do and the text size looks right between non-retina and retina devices. The only catch I’ve found is that iOS has no TextAscent property so I assume the ascent is about ¾ of the text height, e.g.:

  dim textHeight as double = b.Graphics.TextLineSize(value).Height * .75
  dim scaleWidth as integer = width * scale
  dim scaleHeight as integer = height * scale
  dim x as integer = 0
  dim y as integer = scaleHeight - ((scaleHeight - textHeight) / 2)
  b.Graphics.DrawTextBlock(value, x, y, scaleWidth, scaleHeight, alignment)

I’d like to acknowledge @Michel Bujardet for that tip. :slight_smile:

That seems to do it, thanks Jason!

Also, there is an Ascent property for iOSFont, just no TextAscent like it is named on Desktop.

Cool. I’ll update my code. :slight_smile:

I just compared between iOS Font.Ascent and Graphics.TextAscent. I had to multiply the size in OS X by 100 to get more precision as iOS is returning a double, but for instance Courier 36 give 27.14 point ascent in both.

The approximation I advised before works perfectly for standard fonts, but for some unusual, script fonts for instance, it can make a big difference, and Ascent is better IMHO.