I am trying to access pixel data of screen. Very strangely the method worked for ipad 3, but failed on ipod touch 4. First, I used some lines from FastBlurredNotificationCenter to grab a UIImage from the screen:
IOSurfaceRef surface = [UIWindow createScreenIOSurface];
UIImage *imageui = [[UIImage alloc] _initWithIOSurface:surface scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];
This surely works on both devices.
Then, I tried to get a CGImage from UIImage:
CGImageRef imagecg = imageui.CGImage
This code doesn't work on ipod(cgimage size={0,0}). So I assume the UIImage may be created from CIImage and added a line to test:
NSLog(@"debug-ciimage:%@-cgimage:%@",imageui.CIImage,imageui.CGImage);
Both results are "null". I don't know how else to access pixel data of UIImage execpt from its CGImage or PNG representation. Please help...
list of methods tried: 1. [UIImage CGImage]; 2. [UIImage CIImage]; 3. [UIImage drawInRect:imageRect]; (with context given by UIGraphicsBeginImageContextWithOptions(contextsize, NO, 0.0f);)
add:
Solved the problem in a way. But the image type of UIImage created from IOSurface is still unknown...
The solution is to avoid that UIImage that I can't deal with...
From the iphonedevwiki, there is an alternative for
-(id)initWithIOSurface:(IOSurfaceRef)ioSurface;
that is
CGImageRef UICreateCGImageFromIOSurface(IOSurfaceRef ioSurface);
It works on both devices.
The conclusion is that initWithIOSurface is suitable for you if you want to use it on UIView, otherwise use UICreateCGImageFromIOSurface so that you can easily convert it to what you like.
Thanks to JustSid for helping my 1st question on stackoverflow.