2009-07-10 3 views
2

흰색 배경을 가진 UIImage (사용자 도면에 의해 생성 됨)가 있습니다. 이 이미지의 흰색 부분을 투명하게 만들고 싶습니다. 이 파일을 PNG 파일에 저장하고 싶습니다.아이폰에서 흰색이 투명 해 지도록 UIImage를 마스크하는 방법은 무엇입니까?

포럼을 둘러 보았지만 이미지를 올바르게 마스킹하는 방법을 알 수 없습니다. 아무도 전에 이것을 시도 했습니까?

감사합니다.

+1

중복 : http://stackoverflow.com/questions/633722/how-to-make-one-color-transparent-on-a-uimage –

답변

0

시작 UIImage를 완전히 투명하게 만들고 그 뒤에 UIImageView가 완전히 흰색 인 다른 UIImageView를 만들 수 있습니다.

0

원시 데이터를 확인하고 흰색 픽셀을 찾고 해당 픽셀의 알파를 수정 한 다음 새 NSData 객체에 저장 한 다음이를 PNG로 변환해야합니다.

어렵지는 않지만 사소한 것은 아닙니다. 이 같은

3

시도 뭔가 ... 오히려 긴 Quartz2d Programming Guidethis mailing list message 호흡에서

CGImageRef myMaskedImage = [myImage CGImage]; 
const float whiteMask[6] = { 255,255,255, 255,255,255 }; 
CGImageRef myColorMaskedImage = CGImageCreateWithMaskingColors(image, whiteMask); 

CGDataProviderRef provider; 
CGImageRef myPngImage = CGImageCreateWithPNGDataProvider(provider, NULL, true, kCGRenderingIntentDefault); 

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt: 72], kCGImagePropertyDPIHeight, [NSNumber numberWithInt: 72], kCGImagePropertyDPIWidth, nil]; 
CGImageDestinationRef destRef = CGImageDestinationCreateWithURL ((CFURLRef)outPath, (CFStringRef)@"image.png" , 1, NULL); 
CGImageDestinationAddImage(destRef, myPngImage, (CFDictionaryRef)options); 
CGImageDestinationFinalize(destRef); 
CGRelease(destRef); 

CGImageRelease(myColorMaskedImage); 
CGImageRelease(myPngImage); 

.

관련 문제