- (void) decodeStaticImage:(NSBitmapImageRep*) inBitmap
{
ZXBinaryBitmap* zxbitmap = [someZXobject convert: inBitmap];
ZXDecodeHints* hints = [[[ZXDecodeHints alloc] init] autorelease];
ZXQRCodeReader* reader = [[[ZXQRCodeReader alloc] init] autorelease];
ZXResult* result = [reader decode:zxbitmap hints:hints];
[captureDelegate captureResult:self result:result];
}
// ----------------------------------------------------------------------------------------------
- (CGImageRef) makeCGImageFromNSImage:(NSImage*) inImage
{
CGImageRef result;
NSData* imagedata = [inImage TIFFRepresentation];
NSBitmapImageRep* bitmaprep = [[NSBitmapImageRep imageRepWithData:imagedata] retain];
size_t rowBytes = [bitmaprep bytesPerRow];
size_t wid = [bitmaprep pixelsWide];
size_t hgt = [bitmaprep pixelsHigh];
size_t bpp = [bitmaprep bitsPerPixel];
size_t spp = [bitmaprep samplesPerPixel];
CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)imagedata);
CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGBitmapInfo bitsInfo = kCGImageAlphaLast;
result = CGImageCreate(wid,hgt,spp,bpp,rowBytes,
colorspace,bitsInfo,provider,NULL,NO,
kCGRenderingIntentDefault);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorspace);
return(result);
}
//==========================================
- (void) decodeStaticImage:(NSImage*) inImage
{
NSLog(@"ZXCapture::decodeStaticImage - ENTER");
CGImageRef cgImage = [self makeCGImageFromNSImage:inImage];
ZXCGImageLuminanceSource* source = [[ZXCGImageLuminanceSource alloc] initWithCGImage:cgImage]
ZXHybridBinarizer* binarizer = [ZXHybridBinarizer alloc];
[[binarizer initWithSource:source] autorelease];
ZXBinaryBitmap* bitmap = [[[ZXBinaryBitmap alloc] initWithBinarizer:binarizer] autorelease];
@try
{
ZXDecodeHints* hints = [[[ZXDecodeHints alloc] init] autorelease];
ZXQRCodeReader* reader = [[[ZXQRCodeReader alloc] init] autorelease];
ZXResult* result = [reader decode:bitmap hints:hints];
[captureDelegate captureResult:self result:result];
}
@catch (ZXReaderException* rex)
{
NSLog(@"ERROR ZXCapture::decodeStaticImage - failed to decode, caught ReaderException [%@]",
rex.reason);
}
@catch (ZXIllegalArgumentException* iex)
{
NSLog(@"ERROR ZXCapture::decodeStaticImage - failed to decode, caught IllegalArgumentException '%@'",
iex.reason);
}
@catch (id ue)
{
NSLog(@"ERROR ZXCapture::decodeStaticImage - Caught unknown exception: %@", ue);
}
}
but did not work on this image taken with the camera in my iPhone....