将完整的 UIImageView 渲染为位图图像 [英] Render a full UIImageView to a bitmap image

查看:30
本文介绍了将完整的 UIImageView 渲染为位图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何将普通 UIView 渲染为位图图像:

I know how to render a normal UIView to a bitmap image:

UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *bitmapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

问题是,如果 view 是一个 UIImageView,并且带有从 resizableImageWithCapInsets: 返回的拉伸可调整大小的图像,bitmapImage> 这样得到的是原始图像——未拉伸的图像——而不是真正显示的拉伸图像.我可以很容易地通过 bitmapImageview 之间的大小差异来判断.所以我的问题是如何呈现由 UIImageView 显示的全部内容,其图像是一个拉伸的可调整大小的图像?

The problem is that if view is a UIImageView with a stretched resizable image returned from resizableImageWithCapInsets:, bitmapImage gotten this way is the original image — the un-stretched one — instead of the really displayed stretched image. I can easily tell that by the size difference between bitmapImage and view. So my question is how to render the full content displayed by a UIImageView whose image is a stretched resizable image?

推荐答案

我是个白痴!代码完美运行.我只是在别的地方搞砸了一些东西.愚蠢的是,我将代码放在 UIView 类别的方法中,但我将该方法命名为 image.它适用于一般的 UIView ,但由于 UIImageView 有自己的 image 方法,而 UIImageViewUIView, UIImageViewimage 方法在我尝试获取位图图像时被调用.

I'm an idiot! The code is perfectly working. I just messed up something somewhere else. The stupid thing is that I put the code in a method of my UIView category but I named the method image. It works perfectly for general UIViews, but as UIImageView has its own image method and UIImageView is a subclass of UIView, UIImageView's image method is called when I tried to get my bitmap image.

这篇关于将完整的 UIImageView 渲染为位图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆