在UIImageView
&添加厚圆形边框时将其大小调整为椭圆形状,在UIImageView
的角落添加尖峰,截取UIImageView
并保存为png。
1)添加圆角边框时的默认视图
2)将UIImageView
调整为椭圆形
3)将截图保存为.png文件
我尝试使用以下代码捕获屏幕截图
-(UIImage *)captureImage
{
//Capture entire screen
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
UIGraphicsBeginImageContextWithOptions(appDelegate.templateFlag.view.frame.size, appDelegate.templateFlag.view.opaque, 1.5);
}
else
{
UIGraphicsBeginImageContextWithOptions(appDelegate.templateFlag.view.frame.size, appDelegate.templateFlag.view.opaque, 2.0);
}
[appDelegate.viewController.vwEditorPanel.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
以下代码用于在Doc目录中保存image
-(void)saveImage
{
NSData *data = [NSData dataWithData:UIImagePNGRepresentation([self captureImage])];
//Store image in document folder
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",self.strProjectId]];
[data writeToFile:savedImagePath atomically:NO];
}