java argb_如何使用原始ARGB数据创建颜色位图(CGBitmapContextCreate)

我得到一个图像,但我失去了1个字节 . 我的结果图像:

da387ddd-3b3d-4692-a3e1-0471cf97fd9c.png

我想使用argb raw (void*)data 创建color / rgba位图,我有它的宽度和高度 . 在后端(c)我有 decoded rgb to argb 使用以下方法,然后给 input as (void)pData* ,

void decode_rgb_to_argb(U8Data r, U8Data g, U8Data b, U32Data argb, u_int elements)

{

assert(argb);

assert(r);

assert(g);

assert(b);

assert(elements);

unsigned char*p=NULL;

for(u_int i=0;i

{

p=(unsigned char*)(argb+i);

*p=b[i];

p++;

*p=g[i];

p++;

*p=r[i];

p++;

*p=0;

}

}

pData = decode_rgb_to_argb;

//I am handling in ios

-(uiimage*) createBitmap:(void*)pData pWidth:(u_int)pWidth pHeight:(u_int)pHeight{

// Here i want to write ppm file using pData to check wether 4byte/3byte.

NSData* data = [NSData dataWithBytes:pData length:pWidth*pHeight];

char* myBuffer = (char*)pData;

char* rgba = (char*)malloc(pWidth*pHeight*4);

for(int i=0; i < pWidth*pHeight; i++) {

rgba[4*i] = myBuffer[3*i];

rgba[4*i+1] = myBuffer[3*i+1];

rgba[4*i+2] = myBuffer[3*i+2];

rgba[4*i+3] = 255; //or 0

}

size_t bitsPerComponent = 8;

size_t bytesPerRow = pWidth*4;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGContextRef bitmapContext = CGBitmapContextCreate(

// Here i have given my raw data(pData) and rgba buffer

(u_char*)pData,

pWidth,

pHeight,

bitsPerComponent,

bytesPerRow,

colorSpace,

//Here i have used kCGImageAlphaFirst because i am getting data as ARGB,but

//bitmap is not creating.If i use kCGImageAlphaNoneSkipLast, i am getting expected

//image but i'm loosing one byte(alpha).

kCGImageAlhaInfo

);

CFRelease(colorSpace);

CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);

UIImage *result = [[[UIImage imageWithCGImage:cgImage] retain] autorelease];

CGColorSpaceRelease(colorSpace);

CGImageRelease(cgImage);

CGContextRelease(bitmapContext);

return result;

}

如何编写ppm文件,如何从原始 (void*)Pdata 创建位图到ios中的彩色图像?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值