Closed neacao closed 5 years ago
Can you show me the code you are using to display the scanning rectangle?
I believe you are using lastScannedImage
?
@benjohnde yes, i was displaying lastScannedImage, is it correct ?
ZXCapture.m
-(void)captureOutput: ... {
...
CGImageRef rotatedImage = [self createRotatedImage:videoFrameImage degrees:self.rotation];
CGImageRelease(videoFrameImage);
self.lastScannedImage = rotatedImage;
[self.delegate willProcessImage: self.lastScannedImage];
...
}
ViewController.m
-(void)viewDidLoad {
...
_thumbnailView = [[UIImageView alloc] initWithFrame: CGRectMake(20, 20, 100, 100)];
_thumbnailView.contentMode = UIViewContentModeScaleAspectFit;
_thumbnailView.backgroundColor = [UIColor brownColor];
[self.view addSubview: _thumbnailView];
...
}
#pragma mark - ZXCaptureDelegate Methods
-(void)willProcessImage:(CGImageRef)image {
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *img = [UIImage imageWithCGImage: image];
dispatch_async(dispatch_get_main_queue(), ^{
self.thumbnailView.image = img;
});
});
}
Fore more information, both of luminanceLayer
& my custom code return same result of incorrect scan rect
Yeah that is basically correct, weird.
I don't see a false note in the code.
In ZXCapture.m:
// If scanRect is set, crop the current image to include only the desired rect
if (!CGRectIsEmpty(self.scanRect)) {
CGImageRef croppedImage = CGImageCreateWithImageInRect(videoFrameImage, self.scanRect);
CGImageRelease(videoFrameImage);
videoFrameImage = croppedImage;
}
CGImageRef rotatedImage = [self createRotatedImage:videoFrameImage degrees:self.rotation];
CGImageRelease(videoFrameImage);
self.lastScannedImage = rotatedImage;
@benjohnde seem likes this relates to #222
Hmm you mean the small overlay (brighter area) does not match with the result thumbnail?
Because that is independent from ZXCapture.
That's true, should the BarcodeScanner to be updated to correct the scan view frame ?
Yeap, but as the BarcodeScanner should be rewritten in Swift, I wont fix it as of now
You can give it a try 🚀 🎉 :)
@benjohnde to solve this one, the transformVideoRect have to be converted from portrait to landscape if needed. Sample code:
// Correct video frame under Portrait mode cuz the framework will crop before rotate
CGPoint scanPoint = CGPointMake(
transformedVideoRect.origin.y,
self.view.frame.size.width - transformedVideoRect.size.width - transformedVideoRect.origin.x);
CGSize scanSize = CGSizeMake(
transformedVideoRect.size.height,
transformedVideoRect.size.width);
transformedVideoRect = CGRectMake(scanPoint.x, scanPoint.y, scanSize.width, scanSize.height);
Do you want to hand-in a pull request? :)
Sure, I will
PR #444 is ready
Seems like
crop
beforerotate
will return wrong scan view frame, as you can see below, the second image show correct cropped area on the thumbnail view.Crop then rotate
Rotate then crop