如何以全分辨率从 UIImageView 获取旋转、缩放和平移的图像?
问题描述
I have an UIImageView which can be rotated, panned and scaled with gesture recognisers. As a result it is cropped in its enclosing view. Everything is working fine but I don't know how to save the visible part of the picture in its full resolution. It's not a screen grab.
I know I get the UIImage straight from the visible content of the UIImageView but it is limited to the resolution of the screen.
I assume that I have to do the same transformations on the UIImage and crop it. IS there an easy way to do that?
Update: For example, I have an UIImageView with an image in high resolution, let's say a 8MP iPhone 4s camera photo, which is transformed with gestures, so it becomes scaled, rotated and moved around in its enclosing view. Obviously there is some cropping going on so only a part of the image is displayed. There is a huge difference between the displayed screen resolution and the underlining image resolution, I need an image in the image resolution. The UIImageView is in UIViewContentModeScaleAspectFit, but a solution with UIViewContentModeScaleAspectFill is also fine.
This is my code:
The following code creates a snapshot of the enclosing view (superview of faceImageView
with clipsToBounds
set to YES
) using a calculated scale factor.
It assumes that the content mode of faceImageView is UIViewContentModeScaleAspectFit
and that the frame of faceImageView is set to the enclosingView's bounds.
Depending on the current transform the resulting image will have a different size. For example when you zoom in, the size gets smaller. You can also set effectiveScale
to a constant value in order to get an image with a constant size.
Your gesture recognizer code does not limit the scale factor, i.e. you can zoom out/in without being limited. That can be very dangerous! My capture method can output really large images when you've zoomed out very much.
If you have zoomed out the background of the captured image will be black. If you want it to be transparent, you must set the opaque-parameter of UIGraphicsBeginImageContextWithOptions
to NO
.
这篇关于如何以全分辨率从 UIImageView 获取旋转、缩放和平移的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!