gpt4 book ai didi

ios - 目标 - C : Save zoomed caputre image from camera with GPUImage?

转载 作者:行者123 更新时间:2023-11-29 00:59:44 25 4
gpt4 key购买 nike

我已经使用 GPUImage 在相机中完成了缩放功能。但是,当我使用缩放从相机捕获图像并保存时,它仍然保存为普通图片(未找到缩放)。我想在任何模式下捕获必须保存在相册中的图像。我该如何解决这个问题任何建议都会很好。多谢你们。我的代码:

- (void)viewDidLoad {
[super viewDidLoad];
self.library = [[ALAssetsLibrary alloc] init];
[self setViewLayOut];
[self setupFilter];
[self setZoomFunctionlityOnCamera];

}


- (void)setupFilter;
{
videoCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
switch (filterType)
{
case GPUIMAGE_COLORINVERT:
{
self.title = @"Color Negative";
filter = [[GPUImageColorInvertFilter alloc] init];
};
break;
case GPUIMAGE_GRAYSCALE:
{
self.title = @"Black and White Positive";
filter = [[GPUImageGrayscaleFilter alloc] init];
};
break;

default: filter = [[GPUImageFilter alloc] init];
self.title = @"Color Positive";
break;
}
videoCamera.runBenchmark = YES;
filterView = (GPUImageView *)cameraView;
[filter addTarget:filterView];
[videoCamera addTarget:filter];
[videoCamera startCameraCapture];
}



- (IBAction)clickPhotoBtn:(id)sender {
if (!isCameraPermissionAccessed) {
[self showAccessDeinedMessage :@"Camera permission denied" withMessage:@"To enable, please go to settings and allow camera permission for this app."];
return;
}
[videoCamera capturePhotoAsJPEGProcessedUpToFilter:filter withCompletionHandler:^(NSData *processedJPEG, NSError *error){
if (error!=nil)
{
[self showErrorMessage:@"Unable to capture image" ];
return ;
}

else {
UIImage *image = [UIImage imageWithData:processedJPEG];
if (filterType == GPUIMAGE_GRAYSCALE) {
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:image];
GPUImageColorInvertFilter *stillImageFilter = [[GPUImageColorInvertFilter alloc] init];
[stillImageSource addTarget:stillImageFilter];
[stillImageFilter useNextFrameForImageCapture];
[stillImageSource processImage];
UIImage *currentFilteredVideoFrame = [stillImageFilter imageFromCurrentFramebuffer];
UIImageWriteToSavedPhotosAlbum(currentFilteredVideoFrame, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

}
else{
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
}

}];
}

最佳答案

使用下面的代码可能对你有帮助

+(UIImage*)croppedImageWithImage:(UIImage *)image zoom:(CGFloat)zoom
{
CGFloat zoomReciprocal = 1.0f / zoom;

CGPoint offset = CGPointMake(image.size.width * ((1.0f - zoomReciprocal) / 2.0f), image.size.height * ((1.0f - zoomReciprocal) / 2.0f));
CGRect croppedRect = CGRectMake(offset.x, offset.y, image.size.width * zoomReciprocal, image.size.height * zoomReciprocal);

CGImageRef croppedImageRef = CGImageCreateWithImageInRect([image CGImage], croppedRect);

UIImage* croppedImage = [[UIImage alloc] initWithCGImage:croppedImageRef scale:[image scale] orientation:[image imageOrientation]];

CGImageRelease(croppedImageRef);

return croppedImage;
}

关于ios - 目标 - C : Save zoomed caputre image from camera with GPUImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37155071/

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