//The region of the video image that will be scanned, in normalized image coordinates. Note that the video image is in landscape mode (default {{0, 0}, {1, 1}}) - (CGRect)getLandscapeModeScanCropRect:(UIView*)readerView scanView:(UIView*)scanView { CGRect scanCropRect = CGRectMake(0, 0, 1, 1); /*default full screen*/ CGFloat x,y,width,height; x = scanView.frame.origin.x / readerView.bounds.size.width; y = scanView.frame.origin.y / readerView.bounds.size.height; width = scanView.frame.size.width / readerView.bounds.size.width; height = scanView.frame.size.height / readerView.bounds.size.height; scanCropRect = CGRectMake(x, y, width, height); return scanCropRect; } //CGRect scanCrop //The region of the video image that will be scanned, in normalized image coordinates. Note that assuming your coordinates refer to points in portrait orientation, using the default camera image size, located at the default location and taking into account that the camera image is rotated - (CGRect)getPortraitModeScanCropRect:(CGRect)overlayCropRect forOverlayView:(UIView*)readerView { CGRect scanCropRect = CGRectMake(0, 0, 1, 1); /*default full screen*/ float x = overlayCropRect.origin.x; float y = overlayCropRect.origin.y; float width = overlayCropRect.size.width; float height = overlayCropRect.size.height; float A = y / readerView.bounds.size.height; float B = 1 - (x + width) / readerView.bounds.size.width; float C = (y + height) / readerView.bounds.size.height; float D = 1 - x / readerView.bounds.size.width; scanCropRect = CGRectMake( A, B, C, D ); return scanCropRect; }
参考: http://rritw.com/a/caozuoxitong/OS/20130321/327214.html
http://stackoverflow.com/questions/8726370/how-to-crop-scanned-barcode-using-zbar
http://stackoverflow.com/questions/6970350/how-do-i-use-the-scancrop-property-of-a-zbar-reader