last day (14 days later) » 

9:36 AM
1
A: How do I display a self-made bitmap at native resolution in iOS8

wcdCore Graphics drawing is CPU-bound operation. CPU drawing operation is expensive. There is no way to improve the performance. But since you are creating an image, you don't need to do it in main thread. I'm not sure what you are doing in your code snippet. But if I want to draw an image which is...

 
Can you please modify your answer to fit my question? My app reacts to user input and needs to redraw the entire screen after touch events. I have a pointer to the pixel data that I generate quickly and I need to display it fullscreen as quickly as possible. Background processing is not needed nor useful in this case. Where will 'drawBackground' get called from? What's the correct way to draw the entire UIView with my bitmap?
 
wcd
well that can be called anywhere since it just creates an image. For example, user triggered an event, in event handling method, you draw an image and use this image to update the entire screen. For now, I only know you want to draw an image but not sure how you would use this image.
 
That's what I'm asking - how do I use the image to redraw the entire screen if not inside the drawRect method?
 
wcd
that's very easy. You can do stuff like this: backGroundView.layer.contents = (id)background.CGImage if the background view is a general UIView. Or you can use an UIImageView as the background view and just background.image = background. This will update screen.
You should know that if you are drawing in main thread, the main thread will be blocked until the drawing finishes. During drawing your whole app will be frozen which probably makes users unhappy... @BitBank
 
This kind of operation isn't a problem on Android devices. My code takes 2-5ms to update the bitmap data and then Android takes 5-10ms to draw it on the screen and the user doesn't feel the delay. There must be a more efficient way on iOS to simply draw a fullscreen bitmap from a pointer.
 
wcd
9:36 AM
I don't know. Maybe that's because you used drawRect:. When Core Animation detected you defined this method even though it's a empty method does nothing, it will allocate a backing bitmap and cache the result to speed up animation later. This is expensive and useless in most cases. You can try my approach and profile again. I think performance shouldn't be that bad. @BitBank
 
I tried changing the contents of my UIView to the UIImage, but it doesn't paint it on the display.
currentView.layer.contents = (id)image;
This doesn't draw anything
Can you please post code in your answer which creates a bitmap from a byte array pointer and displays it on the screen. This is my original question that you haven't answered. There is no backgroundView inside my UIView.
 
wcd
it's
currentView.layer.contents = (id)image.CGImage;
image is an UIImage object
Is pointer pixels point to actual bitmap data?
I'll edit my answer
 
 
7 hours later…
4:38 PM
Your evidence for whether it is displaying correctly is not correct. You have a formless bitmap and if you set your UIImageView to be AspectFit or some other scaling option, you won't see if it worked or not because it will scale it.
 

last day (14 days later) »