- (UIImage *)createUIImage:(const QCAR::Image *)qcarImage
{
int width = qcarImage->getWidth();
int height = qcarImage->getHeight();
int bitsPerComponent = 8;
int bitsPerPixel = QCAR::getBitsPerPixel(QCAR::RGB888);
int bytesPerRow = qcarImage->getBufferWidth() * bitsPerPixel / bitsPerComponent;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault | kCGImageAlphaNone;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, qcarImage->getPixels(), QCAR::getBufferSize(width, height, QCAR::RGB888), NULL);
CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
UIImage *image = [[UIImage imageWithCGImage:imageRef] retain];
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpaceRef);
CGImageRelease(imageRef);
return image;
}
二,在- (void)renderFrameQCAR中加入下列code
//ZXing
ZxingQRcode* zxing = [ZxingQRcode shareInstance];
QCAR::setFrameFormat(QCAR::RGB888, true);
QCAR::Frame frame = state.getFrame();
for (int i = 0; i < frame.getNumImages(); i++)
{
const QCAR::Image *qcarImage = frame.getImage(i);
if (qcarImage->getFormat() == QCAR::RGB888)
{
UIImage *image = [self createUIImage:qcarImage];
[zxing captureWithUIImage:image];
}
}
三,其中ZxingQRcode是我自己寫的一個class用來控制zxing做解碼之後的動作
這裡要注意的是,QCAR中和zxing中各有一個OverlayView,如果整合的時候不做處理,就會相衝突導致無法compile成功。
(Apple Mach-O Linker Error clang: error: linker command failed with exit code 1)
P.S.在第二項中setFrameFormat是為了用來取得RGB編碼的畫面,
關於畫面編碼QCAR提供了下面幾種選項
/// Pixel encoding types
enum PIXEL_FORMAT {
UNKNOWN_FORMAT = 0, ///< Unknown format - default pixel type for
///< undefined images
RGB565 = 1, ///< A color pixel stored in 2 bytes using 5
///< bits for red, 6 bits for green and 5 bits
///< for blue
RGB888 = 2, ///< A color pixel stored in 3 bytes using
///< 8 bits each
GRAYSCALE = 4, ///< A grayscale pixel stored in one byte
YUV = 8, ///< A color pixel stored in 12 or more bits
///< using Y, U and V planes
RGBA8888 = 16, ///< A color pixel stored in 32 bits using 8 bits
///< each and an alpha channel.
};
沒有留言:
張貼留言