我在保存许多图像时遇到问题。我正在使用 UIGraphicsGetImageFromCurrentImageContext。例如,我的输入图像是 200kb,输出图像只有 35kb。我怎样才能在不损失质量的情况下保存我的图像。这是代码示例:
BOOL first = YES;
mSavedImage = mImageView.image;
UIGraphicsBeginImageContextWithOptions(mImageView.frame.size, YES, 0.0);
DLog(@" FRAME %@",NSStringFromCGSize(mImageView.frame.size));
DLog(@"%i",mEditingView.subviews.count);
for (NSInteger i = mEditingView.subviews.count-1; i>=0; i--){
if ([[mEditingView.subviews objectAtIndex:i] isKindOfClass:[FSShopItem class]]) {
DLog(@"is shopitem");
FSShopItem *lPrewSubview = [mEditingView.subviews objectAtIndex:i];
FSShopItem *lSubview = nil;
if (first) {
[mImageView.image drawInRect:mImageView.frame];
first = NO;
}
else{
lSubview = [mEditingView.subviews objectAtIndex:i+1];
[lSubview.image drawInRect:lSubview.frame];
}
DLog(@" FRAME %@",NSStringFromCGRect(lPrewSubview.frame));
[lPrewSubview.image drawInRect:lPrewSubview.frame];
}
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIImage *lImageForLogo = [UIImage imageNamed:@"ipad_logo.png"];
CGRect lRect = CGRectMake(mEditingView.frame.size.width - lImageForLogo.size.width, mEditingView.frame.size.height - lImageForLogo.size.height, lImageForLogo.size.width, lImageForLogo.size.height);
[lImageForLogo drawInRect:lRect];
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
UIImage *lImageForLogo = [UIImage imageNamed:@"iphone_logo.png"];
CGRect lRect = CGRectMake(mEditingView.frame.size.width - lImageForLogo.size.width, mEditingView.frame.size.height - lImageForLogo.size.height, lImageForLogo.size.width, lImageForLogo.size.height);
[lImageForLogo drawInRect:lRect];
}
mSavedImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return mSavedImage;