我们使用以下代码将png图像从iPhone / iPad保存到媒体库,但尺寸比iPad大。
我们正在使用coreplot来生成图表。使用cofGraph中的imageofLayer保存图像。
CPTGraph *gp = self.hostView.hostedGraph;
self.hostView.bounds = CGRectMake(0,0,640,480);
gp.bounds = CGRectMake(0, 0, 640, 480);
graph.title = txtChartTitle.text;
UIImage *newImage=[gp imageOfLayer ];
NSData *imgData = UIImagePNGRepresentation(newImage);
UIImage* im2 = [UIImage imageWithData:imgData];
CGRect cropRect = CGRectMake(0.0 ,0.0 , 640.0, 480.0);
UIGraphicsBeginImageContextWithOptions(cropRect.size, YES, 0.0);
[im2 drawInRect:cropRect];
UIGraphicsEndImageContext();
[UIPasteboard generalPasteboard].image = im2;
if([self diskSpace]>[imgData length])
{
UIImageWriteToSavedPhotosAlbum(im2, self,@selector(image:didFinishSavingWithError:contextInfo:),nil);
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:@"The chart cannot be saved due to insufficient storage space available."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
alert=NULL;
}