【发布时间】:2012-01-07 22:59:28
【问题描述】:
我正在尝试从相机拍摄照片并覆盖 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;
}
我们将不胜感激。
【问题讨论】:
-
您的视图层次结构是什么样的? self.button 和 self.cameraOverlayView 是同一个超级视图的孩子吗?在调试器控制台中运行
po [[(id)UIApp keyWindow] recursiveDescription]并将输出粘贴到您的问题中。
标签: objective-c ios uibutton camera uiimage