'High'에 해당되는 글 1건

  1. 2010.10.16 [아이폰 앱 개발] high quality유지 resizing
아이폰어플개발정보2010. 10. 16. 10:10
[아이폰 앱 개발] high quality유지 resizing

//   ==============================================================
//      resizedImage
//      ==============================================================
// Return a scaled down copy of the image.  

UIImage* resizedImage(UIImage *inImage, CGRect thumbRect)
        CGImageRef                      imageRef = [inImage CGImage];
        CGImageAlphaInfo        alphaInfo = CGImageGetAlphaInfo(imageRef);
        // There's a wierdness with kCGImageAlphaNone and CGBitmapContextCreate
        // see Supported Pixel Formats in the Quartz 2D Programming Guide
        // Creating a Bitmap Graphics Context section
        // only RGB 8 bit images with alpha of kCGImageAlphaNoneSkipFirst, kCGImageAlphaNoneSkipLast, kCGImageAlphaPremultipliedFirst,
        // and kCGImageAlphaPremultipliedLast, with a few other oddball image kinds are supported
        // The images on input here are likely to be png or jpeg files
        if (alphaInfo == kCGImageAlphaNone)
                alphaInfo = kCGImageAlphaNoneSkipLast;

        // Build a bitmap context that's the size of the thumbRect
        CGContextRef bitmap = CGBitmapContextCreate(
                                thumbRect.size.width,           // width
                                thumbRect.size.height,          // height
                                CGImageGetBitsPerComponent(imageRef),   // really needs to always be 8
                                4 * thumbRect.size.width,       // rowbytes

        // Draw into the context, this scales the image
        CGContextDrawImage(bitmap, thumbRect, imageRef);

        // Get an image from the context and a UIImage
        CGImageRef      ref = CGBitmapContextCreateImage(bitmap);
        UIImage*        result = [UIImage imageWithCGImage:ref];

        CGContextRelease(bitmap);       // ok if NULL

        return result;

Posted by 오늘마감

댓글을 달아 주세요