我正在对图像的某个部分进行处理,我正在使用以下代码,但在 imageToDoProce 上检索到的图像总是被放大,如果我可以缩小这张照片,我的应用程序将完成。用户不会查看这张照片,因此我不想使用 Pinch/UIScrollView。我只需要一种方法来缩小照片,或者有人指导我解决我的代码中的错误,让照片放大。谢谢
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
[connection setVideoOrientation:AVCaptureVideoOrientationPortrait];
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer,0);
uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
size_t width= CVPixelBufferGetWidth(imageBuffer);
size_t height=CVPixelBufferGetHeight(imageBuffer);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(baseAddress, 640, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGRect rect = CGRectMake(0,200,320,48);
CGImageRef newImage = CGBitmapContextCreateImage(context);
UIImage *imageRef= [UIImage imageWithCGImage:CGImageCreateWithImageInRect(newImage, rect) scale:1 orientation:UIImageOrientationUp];
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
UIImage *imageToDoProce = imageRef;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 200, 320, 48)]; // frame is a CGRect.
imageView.image = imageToDoProce;
// UIImage* croppedImage = [CameraImageHelper croppedImageWithImage:imageView.image zoom:2];
NSString*ret= [self DoProcess:imageView.image];
//NSLog(@"obj=%@",[CameraImageHelper getSendResult]);
NSLog(@"rec=%@",ret);
dispatch_async(dispatch_get_main_queue(), ^{
[[CameraImageHelper getSendResult].res1 setText:ret];
[[CameraImageHelper getSendResult].image123 setImage:imageToDoProce] ;
});
}