这就是我想要做的
- 创建一个 UIImage 视图。
- 在上面画一些
- 按共享按钮将图像与上面的图纸共享。
我的代码在 iPad 和 iPhone 上完美运行。问题来自视网膜显示器。所以我的猜测是一些规模没有正确处理,但不确定我做错了什么。这是我的代码
// Create the UIImageView named centerCanvas
// Do the drawing
CGPoint origin = centerCanvas.frame.origin;
CGSize size = centerCanvas.frame.size;
CGSize screenSize = [self returnScreenSize];
CGRect rect = CGRectMake(origin.x, origin.y, size.width, size.height);
UIGraphicsBeginImageContext(screenSize);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], rect);
[shareView setImage:[UIImage imageWithCGImage:imageRef]];
-(CGSize) returnScreenSize
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale,screenBounds.size.height * screenScale);
return screenSize;
}