我有一个允许用各种背景颜色书写的应用程序。当我调用该方法捕获写入照片库的方法时,我得到了写作但没有任何背景颜色。
我可以帮助找出原因..
我用以下方法简单地绘制背景颜色:
drawImage.backgroundColor = [UIColor someColor];
drawImage定义为UIImageView
。
我写给drawImage ok:
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
savedImage.image = drawImage.image;
UIGraphicsEndImageContext();
写入照片库是这样的:
UIImageWriteToSavedPhotosAlbum(drawImage.image, self, nil, nil);
我很感激任何建议。
由于
答案 0 :(得分:0)
我得到了Apple Dev的帮助。论坛,所以我想我会在这里发帖帮助其他人(以及更多评论):
CGImageRef UIGetScreenImage(void);
然后
-(void)captureToPhotoAlbum {
NSLog(@"%s", __FUNCTION__);
// Get image to save
CGImageRef screen = UIGetScreenImage();
UIImage *img = [UIImage imageWithCGImage:screen];
// Image cropping
CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], CGRectMake(0.0f, 70.0f, 768.0f, 768.0f));
UIImage *img2Save = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
// Request to save the image to camera roll
UIImageWriteToSavedPhotosAlbum(img2Save, self, nil, nil);
}