gpt4 book ai didi

iphone - 不使用捏合/UIScrollView 缩小照片

转载 作者:行者123 更新时间:2023-11-29 03:56:54 24 4
gpt4 key购买 nike

我正在对图像的某个部分进行处理,我使用以下代码,但在 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] ;
});
}

最佳答案

在“CameraImageHelper”类中将内容模式设置为 image123

[image123 setContentMode:UIViewContentModeScaleAspectFit];

希望这对你有帮助:)

关于iphone - 不使用捏合/UIScrollView 缩小照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16381000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com