将屏幕截图保存为带有粗圆边框的png时,在图像的边角添加了尖峰

时间:2013-06-13 10:37:05

标签: objective-c uiimageview screenshot

UIImageView&添加厚圆形边框时将其大小调整为椭圆形状,在UIImageView的角落添加尖峰,截取UIImageView并保存为png。

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

Default view when rounded border is added

2)将UIImageView调整为椭圆形

Resized imageview as elliptical shape

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

After saving screenshot as .png file

我尝试使用以下代码捕获屏幕截图

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

0 个答案:

没有答案