ofxiPhoneScreenGrab image compression

hi, im noticing image compression when using ofxiPhoneScreenGrab to take a screen grab in my iphone and ipad app.

is there a way of taking a lossless screengrab in OF?

thanks,
L.

i knew id come back to this problem at some stage…
and this time with a solution :slight_smile:

you’ll need to change this code in ofxiPhoneScreenGrab() function from,

  
  
  
UIImage *image = [[UIImage alloc] initWithCGImage:imageRef];  
CGImageRelease(imageRef);  
	  
SaveDelegate *saveDelegate = [SaveDelegate new];  
saveDelegate.delegate = delegate;  
UIImageWriteToSavedPhotosAlbum(image, saveDelegate, @selector(image:didFinishSavingWithError:contextInfo:), nil);  
  
  

to =>

  
  
  
UIImage* image = [ UIImage imageWithCGImage : imageRef ];      // make image from CGRef  
NSData* imageData = UIImagePNGRepresentation ( image );           // get PNG representation  
UIImage* imageLossless = [ UIImage imageWithData : imageData ];        // wrap UIImage around PNG representation  
CGImageRelease(imageRef);  
      
SaveDelegate *saveDelegate = [SaveDelegate new];  
saveDelegate.delegate = delegate;  
UIImageWriteToSavedPhotosAlbum(imageLossless, saveDelegate, @selector(image:didFinishSavingWithError:contextInfo:), nil);  
  
  

this forces the image to be saved as a PNG with no compression.

L.

This is gold! thanks a lot for sharing

Using this code throws an error in line 97:
UIApplicationMain(nil, nil, nil, @“ofxiPhoneAppDelegate”);
in the ofAppiPhoneWindow.mm file

The error:
2012-04-25 21:11:34.588 SpringMesh[9139:707] -[UIImage imageWithCGImage:]: unrecognized selector sent to instance 0x13c19a0
2012-04-25 21:11:34.590 SpringMesh[9139:707] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[UIImage imageWithCGImage:]: unrecognized selector sent to instance 0x13c19a0’
*** First throw call stack:
(0x33c3b88f 0x3272d259 0x33c3ea9b 0x33c3d915 0x33b98650 0x190c23 0x4de0 0x191723 0x195bb9 0x32bbd60d 0x33c0fa33 0x33c0f699 0x33c0e26f 0x33b914a5 0x33b9136d 0x3310f439 0x35886e7d 0x190ed3 0x19a76b 0x2a10 0x292c)
terminate called throwing an exceptionkill

I’m using OF iPhone preRelease v007

hey nardove,
strange… it was working for me outside OF but when i plugged it into OF, it was giving me the same error.
will look into it.

FYI, this issue has been resolved in upcoming OF 0072