我有一个带有滑块和背景图像的视图。背景图像根据滑块更新,其中滑块控制过滤器的级别。
我正在使用这个框架https://github.com/BradLarson/GPUImage来处理带有过滤器的图像。
从下面的代码中,图像正在使用滑块进行更新,并且过滤器工作得很好。但是我试图在过滤器处理后保存图像(在另一个类中设置 UIImage),但我无法实现这一点(过滤后的图像未保存,但保存了 ufiltered 图像)...我保存图片不对,格式不对?
请帮助我,我已经在这几个小时了!
- (void)loadView
{
CGRect mainScreenFrame = [[UIScreen mainScreen] applicationFrame];
GPUImageView *primaryView = [[GPUImageView alloc] initWithFrame:mainScreenFrame];
self.view = primaryView;
*imageSlider = [[UISlider alloc] initWithFrame:CGRectMake(25.0, mainScreenFrame.size.height - 50.0, mainScreenFrame.size.width - 50.0, 40.0)];
[imageSlider addTarget:self action:@selector(updateSliderValue:) forControlEvents:UIControlEventValueChanged];
imageSlider.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
imageSlider.minimumValue = 0.0;
imageSlider.maximumValue = 1.0;
imageSlider.value = 0.5;
[primaryView addSubview:imageSlider];
[self setupDisplayFiltering];
- (IBAction)updateSliderValue:(id)sender
{
CGFloat midpoint = [(UISlider *)sender value];
[(GPUImageBrightnessFilter *)sepiaFilter setBrightness:midpoint];
//[(GPUImageSepiaFilter *)sepiaFilter setIntensity:[(UISlider *)sender value]];
//[(GPUImageSaturationFilter *)sepiaFilter setSaturation:midpoint];
//[(GPUImageRGBFilter *)sepiaFilter setGreen:midpoint];
[sourcePicture processImage];
}
- (void)setupDisplayFiltering;
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *imageToUseData = [defaults dataForKey:@"imageToUse"];
UIImage *inputImage = [UIImage imageWithData:imageToUseData];
sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
//sepiaFilter = [[GPUImageSepiaFilter alloc] init];
sepiaFilter = [[GPUImageBrightnessFilter alloc] init];
GPUImageView *imageView = (GPUImageView *)self.view;
[sepiaFilter forceProcessingAtSize:imageView.sizeInPixels]; // This is now needed to make the filter run at the smaller output size
[sourcePicture addTarget:sepiaFilter];
[sepiaFilter addTarget:imageView];
[sourcePicture processImage];
UIImage *outputImage = [sepiaFilter imageFromCurrentlyProcessedOutput];
UIImage *quickFilteredImage = [brightnessFilter imageByFilteringImage:inputImage];
// set the image chosen for other classes to set uiimages with
NSData *imageToStore = UIImageJPEGRepresentation(outputImage, 100);
[defaults removeObjectForKey:@"imageToUse"];
[defaults setObject:imageToStore forKey:@"imageToUse"];
}