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: Vinay Prabhu <email@hidden>
- Date: Thu, 27 Jul 2006 17:15:36 +0530
- Importance: Normal
Thanks for the help,
the problem was using the same index variable for both source and dest.
I have used different variables for source and destination, which solved the
problem.
-----Original Message-----
From: Pascal Pochet [mailto:email@hidden]
Sent: Thursday, July 27, 2006 4:36 PM
To: Cocoa List
Cc: Vinay Prabhu
Subject: Re: How to convert 32bit to 24 bit NSBitmapImageRep
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
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s)and may contain confidential or privileged information. If you are not the intended recipient, please notify the sender or 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