问题描述
我有一个gdi引擎,可以生成标准的bmp位流,现在我想通过iphone的CG显示它,我这样使用:
// size->图片大小
//矩形->当前视图rect
// pBits-> BITMAPINFO图像位流
long imgSizePerRow =((long)(24 * size.width + 31)/ 32)* 4;
CGDataProviderRef providerRef = CGDataProviderCreateWithData(NULL,pBits,
imgSizePerRow * size.height,NULL);
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGImageRef imageRef = CGImageCreate(size.width,size.height,8,24,
imgSizePerRow,colorSpaceRef,
kCGBitmapByteOrderDefault,providerRef,
NULL,是,kCGRenderingIntentDefault );
CGContextDrawImage(context,rect,imageRef);
CGImageRelease(imageRef);
CGColorSpaceRelease(colorSpaceRef);
CGDataProviderRelease(providerRef);
注意:我检查行像素是否适合4倍的时间
我的gdi生成位流,在这种情况下,为R8G8B8格式,没有alpha通道,我将其用于CGDataProviderRef并将CGImage绘制到我的视图中。
奇怪的是图像的颜色似乎发生了变化,但是整个形状看起来还不错,我之前通过BITMAP FORMAT将位流保存到了文件中,并进行了对比,仅整个颜色空间就一切正常。 p>
任何人都可以告诉我代码的错误在哪里,否则我会错过一些段落。
我错过了重要的一点:我的GDI位图流按B8-> G8-> R8排序。 p>
i have a gdi engine that result in the standard bmp bits stream ,and now i wanna to display it by the CG in iphone , i use it like this:
// size -> image size
// rect -> current view rect
// pBits -> the BITMAPINFO image bits stream
long imgSizePerRow = ((long)(24 * size.width + 31) / 32) * 4;
CGDataProviderRef providerRef = CGDataProviderCreateWithData(NULL, pBits,
imgSizePerRow * size.height, NULL);
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGImageRef imageRef = CGImageCreate(size.width, size.height, 8, 24,
imgSizePerRow, colorSpaceRef,
kCGBitmapByteOrderDefault, providerRef,
NULL, YES, kCGRenderingIntentDefault);
CGContextDrawImage(context, rect, imageRef);
CGImageRelease(imageRef);
CGColorSpaceRelease(colorSpaceRef);
CGDataProviderRelease(providerRef);
attention: i check the row pixel fit to the times of 4
My gdi generate the bits stream , in this case , R8G8B8 format , no alpha channel ,i use this for CGDataProviderRef and draw the CGImage to my view.it is strange that the image's color seems change, yet the whole shape seems ok , i save the bits stream by BITMAP FORMAT to a file before, and make a contrast , everything seems ok just the whole color space.
CAN anyone tell me where is my fault in the code, or i miss some para. setting?
I missed the important point: my GDI bitmap stream is sequenced by B8->G8->R8.
这篇关于为什么带有标准BMP位数据的iPhone CGImageCreate给出错误的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!