我有图像,我只需要生成 alpha 坐标的图像......我做了以下但它只产生红色图像我在代码中做错了......
在此先感谢.... myCode:
-(UIImage*)alphaAlone:(UIImage*)sourceImage
{
CGImageRef img=sourceImage.CGImage;
CFDataRef m_DataRef;
m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(img));
UInt8 *dataMasked=(UInt8 *)CFDataGetBytePtr(m_DataRef);
double length=CFDataGetLength(m_DataRef);
NSLog(@"length::%f",length);
for(int index=0;index<length;index+=4)
{
dataMasked[index] =dataMasked[index];
dataMasked[index+1] =0;
dataMasked[index+2] =0;
dataMasked[index+3] =0;
}
NSUInteger width =CGImageGetWidth(img);
size_t height=CGImageGetHeight(img);
size_t bitsPerComponent=CGImageGetBitsPerComponent(img);
size_t bitsPerPixel=CGImageGetBitsPerPixel(img);
size_t bytesPerRow=CGImageGetBytesPerRow(img);
NSLog(@"the w:%u H:%lu",width,height);
CGColorSpaceRef colorspace=CGImageGetColorSpace(img);
CGBitmapInfo bitmapInfo=CGImageGetBitmapInfo(img);
CFDataRef newData=CFDataCreate(NULL,dataMasked,length);
CGDataProviderRef provider=CGDataProviderCreateWithCFData(newData);
CGImageRef newImg=CGImageCreate(width,height,bitsPerComponent,bitsPerPixel,bytesPerRow,colorspace,bitmapInfo,provider,NULL,true,kCGRenderingIntentDefault);
return [UIImage imageWithCGImage:newImg];
}