【发布时间】:2012-11-05 08:37:00
【问题描述】:
我有这个功能,可以截取我的应用程序上的一个小UIView,我的问题是我想在这个图像中添加一个位于我的图像文件夹中的背景。我要添加的背景未显示在当前视图上,我只想在保存图像之前以编程方式将其粘贴到屏幕截图图像后面。有可能吗?
(我不想创建一个带有背景的新视图,而不是添加屏幕截图图像,而不是再次拍摄屏幕截图。太多了)
假设这是已拍摄的图像:
______
/ \
/ \
\ /
\______/
这是与图片一起的背景图片:
_________________
| |
| ______ |
| / \ |
| / \ |
| \ / |
| \______/ |
| |
|_________________|
这是我的代码:
- (void)takeScreenShotAndSaveIt:(CGPoint)center
{
// IMPORTANT: using weak link on UIKit
if(UIGraphicsBeginImageContextWithOptions != NULL)
{
UIGraphicsBeginImageContextWithOptions(smallview.frame.size, NO, 0.0);
} else {
UIGraphicsBeginImageContext(smallview.frame.size);
}
[smallview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Save image to iPhone documents directory
NSData * imgData = [[NSData alloc] initWithData:UIImagePNGRepresentation(viewImage)];
NSString * filename = [NSString stringWithFormat:@"MeasureScreenShot.png"];
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSString * path = [documentsDirectory stringByAppendingPathComponent:filename];
[imgData writeToFile:path atomically:YES];
}
【问题讨论】:
标签: iphone objective-c ios uiimageview