[英]How do I correctly place the image from a UIButton into an Image?
我正在尝试从相机拍摄图片并从UIButton覆盖图像-UIButton已被移动/旋转/缩放到屏幕上的某个位置。
下面的代码正确旋转图像,但没有将其放置在正确的X,Y坐标上。
- (UIImage*)dumpOverlayViewToImage {
CGSize imageSize = self.cameraOverlayView.bounds.size;
UIGraphicsBeginImageContext(imageSize);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, self.button.frame.origin.x, self.button.frame.origin.y);
CGContextConcatCTM(ctx, self.button.transform);
[self.button.imageView.image drawAtPoint:CGPointMake(0,0)];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
帮助将不胜感激。
如果您使用的是带有视网膜显示屏的设备,则可能需要考虑到这一点。 在这种情况下,最简单的方法应该是使用它而不是UIGraphicsBeginImageContext
:
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.