Re: How to convert 32bit to 24 bit NSBitmapImageRep
Re: How to convert 32bit to 24 bit NSBitmapImageRep
- Subject: Re: How to convert 32bit to 24 bit NSBitmapImageRep
- From: Pascal Pochet <email@hidden>
- Date: Thu, 27 Jul 2006 13:06:23 +0200
Le 27-juil.-06 à 11:19, Vinay Prabhu a écrit :
Conversion is written like this,
int iImageW = [imageRep pixelsWide];
int iImageH = [imageRep pixelsHigh];
NSBitmapImageRep* pMaskImage = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:nil
pixelsWide:iImageW pixelsHigh:iImageH bitsPerSample:8
samplesPerPixel:3 hasAlpha:NO isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:3*iImageW
bitsPerPixel:24];
unsigned char * imgData = NULL;
imgData = [pMaskImage bitmapData];
unsigned char * src = NULL;
src=[imageRep bitmapData];
int index = 0;
for (int j=0; j<iImageH; j++)
{
for (int i=0; i<iImageW; i++)
{
imgData[index]=src[index];
imgData[index+1]=src[index+1];
imgData[index+2]=src[index+2];
//imgData[index+3]=255; //Alpha data
index+=3;
}
}
Anything wrong in this code?
1. You should not assume that each line has the same number of bytes
as the number of pixels times the number of bytes per pixel,
there is a bytesPerRow method in NSBitmapImagerep to know about the
number of bytes really used for each line in the image…
2. By using the same index variable both for source and destination,
you forgot to skip the alpha of the original 32 bits image…
Pascal Pochet
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden