2

当添加厚圆形边框并将其调整为椭圆形时,在截取屏幕截图并保存为 png时UIImageView,尖峰会添加到 的角上。UIImageViewUIImageView

1) 添加圆角边框时的默认视图

添加圆角边框时的默认视图

2) 调整UIImageView为椭圆形状

将图像视图调整为椭圆形

3) 将屏幕截图保存为 .png 文件后

将屏幕截图保存为 .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;
}

以下代码用于保存image在 Doc 目录中

-(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];
}
4

0 回答 0