thanks! I manage to get it looking right on one device, then as soon as I change to another the graphics go crazy and draw different sizes and in the wrong positions. I’m using accelerated surfaces which gives me the scaled option for the surface and I’m using the density variable from the reflection library to get the screen density but just getting totally confused! I’ll keep triyng. If I’m still stuck in a few days I’ll just post what I’ve done so far and leave it open to someone else to fix it.
Thanks AlwaysBusy (need a better name for you). I have found that the presence of hardware acceleration makes a difference. I wasn’t using gpu support on the emulator as it seems to freeze after a few seconds, but I think that’s graphics driver related on my laptop. But I found the scale changes completely just based on whether GPU support is enabled or not. What I’ll do is only develop for hardware accelerated devices as this should cover most people, my Galaxy S2 phone has it and that’s 3 years old! Expect a new code download available in the next few days.
Just call me Alain 🙂 Interesting facts about the different behaviours when GPU is enabled or not. Wouldn’t have thought this could make such a difference (besides speed).
Always your code for resize bitmap are awesome! But i have one problem! The “bitmap scaled” is not created to center of canvas but on left! There are any solution for this??
I’m not sure the answer to this I’m afraid. I’ve moved onto using the libgdx library for games, which is awesome and much easier to use. I would recommend reading any posts I have made about libgdx as it’s much more advanced than using accelerated surfaces.
Looks great Andy!
thanks! I manage to get it looking right on one device, then as soon as I change to another the graphics go crazy and draw different sizes and in the wrong positions. I’m using accelerated surfaces which gives me the scaled option for the surface and I’m using the density variable from the reflection library to get the screen density but just getting totally confused! I’ll keep triyng. If I’m still stuck in a few days I’ll just post what I’ve done so far and leave it open to someone else to fix it.
Nice try, can’t wait to test it out on my Android devices.
Is it because you’re using B4a 3.2 that you have problems with the sizes/scales or is it
something else?
Asmoro
Not sure if it is of any help but this is the formula I use when I scale graphics in B4A:
iTemplatewidth=800
iTemplateHeight=1280
Dim delta As Double
delta = (100%x + 100%y) / ((iTemplatewidth + iTemplateHeight) * 100dip / 100) – 1
ScaleRate = 1 + 1 * delta
I then develop everything for 800×1280 and use the ScaleRate to adjust per device.
My bitmap scale function then looks something like this (Using ABExtDrawing):
Public Sub MakeBitmapScaleHeight(iPicture As Bitmap, iHeight As Int) As Bitmap
Dim xBuildPicture As Bitmap
Dim xBuildCanvas As Canvas
Dim innerScale As Float
innerScale = iHeight/iPicture.Height
Dim iWidth As Int
iWidth = iPicture.Height * innerScale
xBuildPicture.InitializeMutable(iWidth,iHeight)
xBuildCanvas.Initialize2(xBuildPicture)
Dim paint As ABPaint
paint.Initialize
paint.setDither(True)
paint.setAntiAlias(True)
paint.setFilterBitmap(True)
Dim matrix As ABMatrix
matrix.postScale(innerScale, innerScale)
exDraw.drawBitmap4(xBuildCanvas, iPicture, matrix, paint)
Recycle(iPicture)
Return xBuildPicture
End Sub
Thanks AlwaysBusy (need a better name for you). I have found that the presence of hardware acceleration makes a difference. I wasn’t using gpu support on the emulator as it seems to freeze after a few seconds, but I think that’s graphics driver related on my laptop. But I found the scale changes completely just based on whether GPU support is enabled or not. What I’ll do is only develop for hardware accelerated devices as this should cover most people, my Galaxy S2 phone has it and that’s 3 years old! Expect a new code download available in the next few days.
Just call me Alain 🙂 Interesting facts about the different behaviours when GPU is enabled or not. Wouldn’t have thought this could make such a difference (besides speed).
Always your code for resize bitmap are awesome! But i have one problem! The “bitmap scaled” is not created to center of canvas but on left! There are any solution for this??
I’m not sure the answer to this I’m afraid. I’ve moved onto using the libgdx library for games, which is awesome and much easier to use. I would recommend reading any posts I have made about libgdx as it’s much more advanced than using accelerated surfaces.