将完整的 UIImageView 渲染为位图图像

编程入门 行业动态 更新时间:2024-10-27 11:22:11
本文介绍了将完整的 UIImageView 渲染为位图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我知道如何将普通 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 04:13:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1183980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位图   图像   完整   UIImageView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!