Objective-c UIImage图像质量差

时间:2014-12-18 10:32:19

标签: ios objective-c graphics uiimageview uiimage

我不是最好的平面设计师,但需要设置一些图标。我使用边框等选项制作了gimp。所有主要设计都是1000x1000px,用于UIImageView中的objective-c代码。

我想知道为什么调整大小的图标看起来很可怕。有什么建议吗?

在应用程序中: http://s14.postimg.org/k2g9uayld/Screen_Shot_2014_12_18_at_11_22_53.png http://s14.postimg.org/biwvwjq8x/Screen_Shot_2014_12_18_at_11_23_02.png

原始图片:

不能发布2个以上的链接:s17.postimg.org/qgi4p80an/fav.png

我认为这不重要,但

UIImage *image = [UIImage imageNamed:@"fav.png"];
image = [UIImage imageWithCGImage:[image CGImage] scale:25 orientation:UIImageOrientationUp];
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:image];

但是其中一个图像已经在故事板中设置,效果是一样的。

2 个答案:

答案 0 :(得分:0)

    [self.favO.layer setMinificationFilter:kCAFilterTrilinear];
    [self.favO setImage:[self resizeImage:[UIImage imageNamed:@"fav.png"] newSize:CGSizeMake(35,35)]
                        forState:UIControlStateNormal];

- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize {
    CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
    CGImageRef imageRef = image.CGImage;

    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
    CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height);

    CGContextConcatCTM(context, flipVertical);
    CGContextDrawImage(context, newRect, imageRef);

    CGImageRef newImageRef = CGBitmapContextCreateImage(context);
    UIImage *newImage = [UIImage imageWithCGImage:newImageRef];

    CGImageRelease(newImageRef);
    UIGraphicsEndImageContext();

    return newImage;
}

这个问题已解决。当UIImageView负责调整大小时会发生此问题。

答案 1 :(得分:-1)

为了避免这种行为,我建议你制作SVG而不是png文件。使用lib SVGKit,您可以将其调整为您的心脏内容。由于SVG格式是矢量格式,因此您的缩放不会有任何损失。 https://github.com/SVGKit/SVGKit

编辑: 要添加到此解决方案,您在1000X1000px的PNG文件必须非常繁重,另一方面SVG文件是一个文本文件,因此它非常轻量级

相关问题