[英]Objective-c UIImage bad image quality
我不是最好的圖形設計師,但需要設置一些圖標。 我使用gimp以及Border等選項制作了它們。所有對象主要是在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
原始圖片:
不能發布兩個以上的鏈接,因此: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];
但是,在情節提要中設置了一張圖像,效果是相同的。
[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負責調整大小時會發生此問題。
為了避免這種行為,我建議您制作SVG而不是png文件。 然后,使用lib SVGKit可以將其調整為適合您的內容。 由於SVG格式是矢量格式,因此縮放不會有任何損失。 https://github.com/SVGKit/SVGKit
編輯:要添加到此解決方案,您在1000X1000px的PNG文件必須非常沉重,另一方面,SVG文件是文本文件,因此它非常輕便
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.