简体   繁体   中英

How to programmatically change contrast of PNG image of without background in iPhone objective-c?

I want to programmatically change the contrast of a PNG image which has no background or I must say transparent background. The below image shows the example. 在此处输入图片说明

I am able to change the contrast of with background image. But not able to change it in without background. I have tried this and this But both works in with background Image. Please help me to achieve this or suggest me any solution or tutorial link.

Thanks in advance

CGImageRef inImage = self.CGImage;
CFDataRef m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));  
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);  

int length = CFDataGetLength(m_DataRef);

for (int i=0; i<length; i+=4)
{
    filter(m_PixelBuf,i,context);
}  
CGContextRef ctx = CGBitmapContextCreate(m_PixelBuf,  
                                         CGImageGetWidth(inImage),  
                                         CGImageGetHeight(inImage),  
                                         CGImageGetBitsPerComponent(inImage),
                                         CGImageGetBytesPerRow(inImage),  
                                         CGImageGetColorSpace(inImage),
                                         CGImageGetBitmapInfo(inImage) );     

CGImageRef imageRef = CGBitmapContextCreateImage(ctx);  
CGContextRelease(ctx);
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
CFRelease(m_DataRef);
return finalImage;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM