SORU
26 Mayıs 2011, PERŞEMBE


Nasıl bir Uİİmage küçültün ve gevrek / keskin yapmak için bulanık yerine aynı anda?

Bir görüntü, ama keskin bir şekilde küçültün ihtiyacım var. Örneğin Photoshop resim küçültme seçenekler "Yumuşak" (bulanık) ve "Keskin". çift küplü çift küplü var

Bu görüntü ölçek küçültme algoritması açık kaynaklı veya belgelenmiş bir yere veya SDK yöntemleri bunu yapmak için teklif ediyor?

CEVAP
15 EKİM 2011, CUMARTESİ


Sadece imageWithCGImage yeterli kullanarak. Ölçek, ama sonuç yukarı veya aşağı Ölçekleme olsun bulanık ve yetersiz olacaktır.

Eğer yumuşatma sağ olsun ve "" bir şeye ihtiyacın var böyle: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/. jaggies kurtulmak istiyorsanız

Çalışma test kodumu benim şeffaf PNG ile çalışmak için küçük bir ayarlama ile Trevor'un çözümü olan bu gibi bir şey görünüyor:

- (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();

    // Set the quality level to use when rescaling
    CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
    CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height);

    CGContextConcatCTM(context, flipVertical);  
    // Draw into the context; this scales the image
    CGContextDrawImage(context, newRect, imageRef);

    // Get the resized image from the context and a UIImage
    CGImageRef newImageRef = CGBitmapContextCreateImage(context);
    UIImage *newImage = [UIImage imageWithCGImage:newImageRef];

    CGImageRelease(newImageRef);
    UIGraphicsEndImageContext();    

    return newImage;
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Engadget

    Engadget

    18 EYLÜL 2006
  • sebsebdouze

    sebsebdouze

    7 ŞUBAT 2008
  • SPBedition

    SPBedition

    24 HAZİRAN 2013