'uiimage'에 해당되는 글 2건

  1. 2011.09.27 [Objective-C] UIImage 흑백으로 변경하기(gray)
  2. 2011.09.23 [Objective-C] 이미지 flip 처리
Dev/iOS2011. 9. 27. 16:04


- (UIImage *)convertImageToGrayScale:(UIImage *)image { 

// Create image rectangle with current image width/height 

CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);

// Grayscale color space 

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();

// Create bitmap content with current image size and grayscale colorspace 

CGContextRef context = CGBitmapContextCreate(nil, image.size.width, image.size.height, 8, 0, colorSpace, kCGImageAlphaNone);

// Draw image into current context, with specified rectangle 

// using previously defined context (with grayscale colorspace) 

CGContextDrawImage(context, imageRect, [image CGImage]);

// Create bitmap image info from pixel data in current context 

CGImageRef imageRef = CGBitmapContextCreateImage(context);

// Create a new UIImage object  

UIImage *newImage = [UIImage imageWithCGImage:imageRef];

// Release colorspace, context and bitmap information 

CGColorSpaceRelease(colorSpace);

CGContextRelease(context);

CFRelease(imageRef);

// Return the new grayscale image 

return newImage;

}

파라미터를 추가하면 scale도 변경 가능하네요.


Posted by 놀란
Dev/iOS2011. 9. 23. 16:41


UIImage *origianlImage = [UIImage imageNamed:@"source.png"];

UIImage *flippedImage = [UIImage imageWithCGImage:originalImage.CGImage

scale:1.0 

orientaion:UIImageOrientationLeftMirrored];

orientaion 종류

typedef enum {

    UIImageOrientationUp,            // default orientation

    UIImageOrientationDown,          // 180 deg rotation

    UIImageOrientationLeft,          // 90 deg CCW

    UIImageOrientationRight,         // 90 deg CW

    UIImageOrientationUpMirrored,    // as above but image mirrored along other axis. horizontal flip

    

    UIImageOrientationDownMirrored,  // horizontal flip

    UIImageOrientationLeftMirrored,  // vertical flip

    UIImageOrientationRightMirrored, // vertical flip

} UIImageOrientation;

Posted by 놀란