组合多个 UIImageView 并保持分辨率
我正在设计一个应用程序,用户可以将多个 UIImageView 一个一个地放置。当用户决定将其保存到相册时,我必须组合所有这些 UIImageView 并将其保存到照片库。在组合它们时,我需要保留它们的位置、分辨率、zorder。我尝试的方法是有一个父 UIView,它的作用就像一个容器。用户将所有 UIImageView 放入此 UIView 中。保存时,我截取 UIView 的屏幕截图并保存。尽管这种方法有效,但它并不能保留分辨率。最终图像的分辨率与父UIView尺寸的分辨率相同(宽度和高度均为300像素)。有办法保留分辨率吗?或者至少有更高的分辨率,例如高达 1024 x 768 像素?任何指针/代码示例将不胜感激!
I am designing an application where a user places multiple UIImageViews one over another. When the user decides to save this to photo album, I have to combine all these UIImageViews and save it to Photo Library. While combining them I need to preserve their positions, resolutions, zorder. The approach I tried I was to have a parent UIView which acts like a container. The user places all the UIImageViews inside this UIView. While saving, I take a screenshot of the UIView and save it. Although this approach works, it does not preserve the resolution. The resolution of the final image is same as the resolution of the parent UIView size (width and height being 300 pixels). Is there way to preserve the resolution? or atleast have a higher resolution like upto 1024 x 768 pixels? Any pointers/code examples would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 UIView 的大小高于您拥有的最大图像的大小,那么您正在做的保存 UIView 是一个非常好的主意,但情况几乎从未如此。
您所要做的就是创建一个与最大图像一样大的图形上下文 (CGContextRef),按 z 顺序对图像进行排序,然后开始在那里绘制这些图像。
我会尝试用一些伪代码来帮助您:
希望它有帮助。
What you are doing, saving the UIView, is a very good idea if the size of the UIView is higher than the size of the biggest image you have, but that's almost never the case.
What you have to do is to create a Graphic Context (CGContextRef), as big as the biggest of your images, sort your images by z-order and start drawing those images there.
I'll try to help you with some pseudo code:
Hope it helps.