Skip to content

Instantly share code, notes, and snippets.

@jhaynie
Created July 6, 2010 05:25
Show Gist options
  • Save jhaynie/465046 to your computer and use it in GitHub Desktop.
Save jhaynie/465046 to your computer and use it in GitHub Desktop.
- (void)takePicture:(NSTimer*)theTimer {
CGImageRef capture = UIGetScreenImage();
CGRect cropRect = [overlayView cropRect];
if (oneDMode) {
// let's just give the decoder a vertical band right above the red line
cropRect.origin.x = cropRect.origin.x + (cropRect.size.width / 2) - (ONE_D_BAND_HEIGHT + 1);
cropRect.size.width = ONE_D_BAND_HEIGHT;
// do a rotate
CGImageRef croppedImg = CGImageCreateWithImageInRect(capture, cropRect);
capture = [self CGImageRotated90:croppedImg];
capture = [self CGImageRotated180:capture];
CGImageRelease(croppedImg);
cropRect.origin.x = 0.0;
cropRect.origin.y = 0.0;
cropRect.size.width = CGImageGetWidth(capture);
cropRect.size.height = CGImageGetHeight(capture);
}
UIImage *decodeImage = nil;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] &&
[UIScreen mainScreen].scale > 1.0)
{
UIImage *image = [[[UIImage alloc] initWithCGImage:capture scale:1.0 orientation:UIImageOrientationUp] autorelease];
UIGraphicsBeginImageContextWithOptions(CGSizeMake(320, 480), NO, 1.0);
[image drawInRect:CGRectMake(0, 0, 320, 480)];
decodeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
else
{
#endif
CGImageRef newImage = CGImageCreateWithImageInRect(capture, cropRect);
decodeImage = [[[UIImage alloc] initWithCGImage:newImage] autorelease];
CGImageRelease(newImage);
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
}
#endif
Decoder *d = [[Decoder alloc] init];
d.readers = readers;
d.delegate = self;
[d decodeImage:decodeImage cropRect:cropRect];
CGImageRelease(capture);
}
@jhaynie
Copy link
Author

jhaynie commented Jul 6, 2010

this is a patch for making zxing work with ios4 devices and retina display

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment