iOS Question blurry bitmap draw

sorex

Expert
Licensed User
Longtime User
Hello,

While going on with my pixel tests it's time for ios.

As explained in this B4A thread > https://www.b4x.com/android/forum/threads/lib-accelerated-surface.27462/page-11#post-495188

I'm testing how upscaling pixel images behave.

To my surprice this blury filter is also applied on IOS.

Is there any way to turn this off?

the code used:
Code: Copy
Dim b As Bitmap
Dim i As ImageView
Dim c As Canvas
Dim r As Rect
b.Initialize(File.DirAssets,"bruce.png")
i.Initialize("")
Page1.RootPanel.AddView(i,0,0,100%x,100%y)
c.Initialize(i)
r.Initialize(0,0,160,210)
c.DrawColor(0xff0000ff)
c.DrawBitmap(b,r)
c.Refresh

bruce_blur.png
 
these test is just to see how people who do pixel based games do their thing (ok they use sophisticated things like spriteKit, libGDX but in a lot of cases it's overkill)

and with monster resolutions I expect some serious upscaling unless they store a 16x16 sprite as a 512x512 image.
 
Upvote 0
You need to use ImageViews to show the bitmaps instead of canvas. This is actually much better for performance (see GameView thread for an example).

Use this code to disable antialiasing:
Code: Copy
Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.LoadLayout("1")
   NavControl.ShowPage(Page1)
   ImageView1.Bitmap = LoadBitmap(File.DirAssets, "1.png")
   Dim no As NativeObject = Me
   no.RunMethod("disableAntiAlias:", Array(ImageView1))
End Sub
#if OBJC
- (void) disableAntiAlias:(UIImageView*)v {
   v.layer.magnificationFilter = kCAFilterNearest;
}

SS-2017-04-05_17.54.17.png
 
Upvote 0
that looks more like it :) I will check it out, thanks a lot for checking this out.

why I went for bitmap/canvas... well, accelerated surface and gameview for android uses bitmap aswell.

having nearly the same update code for B4i/B4A makes things a lot easier but I still need to compare speeds.
 
Upvote 0
I confirm that it works on an imageview with plain loadbitmap usage.

Doesn't seem to work once a canvas is used to copy the same bitmap onto the imageview tho.

really strange...

even with anti aliasing disabled all it needs to blur it again is this

Code: Copy
c.Initialize(i)
c.Refresh

and using the anti alias disable trick again doesn't do anything then.

this will give issues when using tilemapping. doing that with dozens of imageviews would be too much I guess.
 
Last edited:
Upvote 0
No. The performance will be better than with Canvas.

indeed it is.

but...

updating the bitmaps of a 10x14 imageview grid makes it look lag sometimes.

it's almost perfect but now it's just a scrolling tilemap without any sprites on top of it so it will get even worse.

I'll try another approach that requires less imageview bitmap updates.

too bad canvas operations aren't accelerated it would've made things easier.
 
Upvote 0
the difference is that your sprites don't changes I guess.

In this case 140 imageviews gets moved around and at certain frames their bitmap data are updated aswell.

I'll test gameview ios aswell.
 
Upvote 0
I just tried with iGameView and the result is about the same as the normal imageview method.
Makes sense as you wrote it's also imageview based unlike the android version which is accelerated canvas.

Will give spriteKit a try but that would need more time as not much examples are available.
 
Upvote 0
Back
Top