相关疑难解决方法(0)

如何在不损失视网膜显示质量的情况下将UIView捕获到UIImage

我的代码适用于普通设备,但在视网膜设备上会产生模糊图像.

有人知道我的问题的解决方案吗?

+ (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContext(view.bounds.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;
}
Run Code Online (Sandbox Code Playgroud)

image-capture scale uikit uiimage retina-display

293
推荐指数
9
解决办法
15万
查看次数

如何模糊效果适用于iOS中的UIView?

在我的应用程序中,我想在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)

但是使用此代码时遇到问题.当应用模糊效果时,时间视图变小.

objective-c blur uiview ios uiblureffect

11
推荐指数
3
解决办法
9967
查看次数

如何拍摄未渲染的UIView的快照?

我使用此方法拍摄快照:

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)呢?

iphone objective-c uiview uiimage ios

5
推荐指数
2
解决办法
4892
查看次数