質問

I'm having problem with saving many images. I'm using UIGraphicsGetImageFromCurrentImageContext. For example my input image is 200kb and output image is just 35 kb. How can i save my images without loss of quality. Here is code example:

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;
役に立ちましたか?

解決

I'll assume that the mImageView.frame.size rectangle is much smaller than the logo.png images, so they are draw in a smaller rectangle than their original size. What you need to do is create a context that is much larger - say 4 or 8 times larger. Now the core image will have much more detail (but of course be larger too). You can then render this image in a smaller rectangle, and lose resolution, or show it at its native size for full resolution.

The key point here is that your are working with pixels - not vector art - and so if you ever draw an image in a smaller rectangle than its native size, you will lose detail.

他のヒント

Rather than directly using the image view frames, decide on how big the result image should be and then mutate the frames with CGRectInset based on the scaling factor between the screen size (the frame coordinate space) and the full size.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top