iPhone imageview 打印屏幕 - 从 imageview 创建新图像
我可以以某种方式以编程方式打印一个 ImageView 的屏幕吗?
假设我正在显示不同尺寸的大照片,自动缩放(AspectFit)到屏幕尺寸,居中且具有黑色背景。我想捕获缩放图像,包括黑色图像视图背景,以便使用 320x480 图像。
那么如何将 350x600 图像更改为带有黑色边框的 320x480 图像,并且没有任何其他元素(按钮、标签)覆盖此图像视图?在 Android 上,我只是捕获屏幕缓冲区,但对于 iPhone,我真的不知道该怎么做...
提前致谢!
Can I somehow programmatically make a print screen of one ImageView?
Let's say I'm displaying big photos, with different sizes, scaled automatically (AspectFit) to screen size, centered and with black background. I would like to capture the scaled image including the black imageview background to have 320x480 image to work with.
So how to change for example 350x600 image to 320x480 with black border and without any other elements (buttons, labels) overlaying this imageview? On Android I'm just capturing screen buffer but for iPhone I really have no idea how to do it...
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
输出
viewImage
。由于您想要一个黑色边框,所以您可以有这样的逻辑,请在 UIView 上添加imageView
,并将blackBackroundColor
设置为黑色(记住此视图的框架应该大于您的 imageView 的框架)框架的每一侧都有一些边距,以便您可以拥有边框).....现在在[.layer renderInContext:UIGraphicsGetCurrentContext()];
使用此方法。The
viewImage
is output. As you want a black border so you can have a logic like this, add youimageView
on a UIView withblackBackroundColor
as black(remember this view's frame should be greater than your imageView's frame with some margin from each side so that you can have your border)..... and now in[<yourView>.layer renderInContext:UIGraphicsGetCurrentContext()];
use this method.希望这有帮助。
Hope this helps.