【发布时间】:2016-12-02 21:32:12
【问题描述】:
我想调整 UIImage 的大小,所以我使用了下面的代码。
UIGraphicsBeginImageContext(size);
[sourceImage drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
以上代码工作正常,但 destImage 的方向发生了变化。我不知道怎么做。
source.imageOrientation = 3
destImage.imageOrientation = 0
谁能告诉我如何调整与 sourceImage 相同方向的图像大小?
已编辑:
UIImage *scaleImage = [UIImage imageWithCGImage:destImage.CGImage
scale:sourceImage.scale orientation:sourceImage.imageOrientation];
已编辑:
我也试过上面的代码。但它仍然给了我相反的方向。
【问题讨论】:
-
Ekata 尝试其他解决方案
-
@fishinear 我使用了那个代码,但它不起作用,这就是我问这个问题的原因。
-
如果你想让人们帮助你,你需要做得比“它没有用”更好。这对我来说可以。在您的问题中明确说明您使用了哪些代码、您期望它做什么以及它做了什么。
-
另一个问题:为什么要目标图片的
imageOrientation属性和原图一样? imageOrientation 说明了在绘制过程中必须如何旋转图像,这正是您执行 drawInRect 时发生的情况。所以目的地的 imageOrientation 为 0 实际上是正确的。
标签: objective-c uiimage image-resizing uigraphicscontext