我的代码适用于普通设备,但在视网膜设备上会产生模糊图像.
有人知道我的问题的解决方案吗?
+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我想在uiview上应用模糊效果.所以我怎样才能实现模糊效果.我试过下面的代码:
UIGraphicsBeginImageContext(scrollview.bounds.size);
[scrollview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Blur the UIImage with a CIFilter
CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage];
CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"];
[gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"];
[gaussianBlurFilter setValue:[NSNumber numberWithFloat:3] forKey: @"inputRadius"];
CIImage *resultImage = [gaussianBlurFilter valueForKey: @"outputImage"];
UIImage *endImage = [[UIImage alloc] initWithCIImage:resultImage];
//Place the UIImage in a UIImageView
UIImageView *newView = [[UIImageView alloc] initWithFrame:scrollview.bounds];
newView.image = endImage;
[scrollview addSubview:newView];
Run Code Online (Sandbox Code Playgroud)
但是使用此代码时遇到问题.当应用模糊效果时,时间视图变小.
我使用此方法拍摄快照:
UIView *snapshotView = [someView snapshotAfterScreenUpdates:NO];
Run Code Online (Sandbox Code Playgroud)
这给了我一个可以玩的UIView.
但是,我需要它的UIImage而不是UIView.
这是我用于将UIView转换为UIImage的方法:
- (UIImage *)snapshotOfView:(UIView *)view
{
UIImage *snapshot;
UIGraphicsBeginImageContext(view.frame.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
snapshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return snapshot;
}
Run Code Online (Sandbox Code Playgroud)
它不起作用,快照是一个空白的UIImage,因为snapshotView没有呈现.
显而易见的事情是直接拍摄视图的快照,而不是以UIView的形式拍摄快照然后转换它.
显而易见的方法的问题是我使用的WKWebView有一个巨大的错误,不允许你截取屏幕截图.这是真的,我甚至报告了这个错误,他们说他们正试图修复它.
那么,如何在不渲染的情况下拍摄snapshotView的快照(UIImage)呢?
ios ×2
objective-c ×2
uiimage ×2
uiview ×2
blur ×1
iphone ×1
scale ×1
uiblureffect ×1
uikit ×1