• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: How to convert 32bit to 24 bit NSBitmapImageRep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 14:49:42 +0530
  • Importance: Normal

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?

-----Original Message-----
From: cocoa-dev-bounces+vinayprabhu=email@hidden
[mailto:cocoa-dev-bounces+vinayprabhu=email@hidden]On
Behalf Of Michael Ash
Sent: Thursday, July 27, 2006 6:36 AM
To: email@hidden
Subject: Re: How to convert 32bit to 24 bit NSBitmapImageRep


On 7/26/06, Vinay Prabhu <email@hidden> wrote:
> Hi,
>
> Is there any direct API to convert from 32 bit to 24 bit NSBitmapImageRep?
>
> I couldn't find any direct way, I have tried 2 methods,
> 1) Obtained the data pointer from 32 bit NSBitmapImageRep, and created new
> image rep
> using the initWithBitmapDataPlanes API.
> This resulted in junk output.
>
> 2) Created a new image rep using the initWithBitmapDataPlanes API by passing
> "nil" for data pointer.
> Then obtained the data pointer using "bitmapData" API and copied the data
> from 32 bit to 24 bit, without passing alpha information.
> This also resulted in junk output
>
> Any better method to do this?

If you can require Tiger, create a 24-bit NSBitmapImageRep, then
create a new NSGraphicsContext from it, and draw your 32-bit rep into
it. This will make the graphics system handle all the annoying
conversions automatically.

If that is not an option, attempt #2 should have worked. If you got
junk output, that just means your conversion was written wrong.

Mike
 _______________________________________________
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
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

  • Follow-Ups:
    • Re: How to convert 32bit to 24 bit NSBitmapImageRep
      • From: Pascal Pochet <email@hidden>
References: 
 >Re: How to convert 32bit to 24 bit NSBitmapImageRep (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: universal/intel zlib in framework
  • Next by Date: SetHidden on two objects... Slow to hide
  • Previous by thread: Re: How to convert 32bit to 24 bit NSBitmapImageRep
  • Next by thread: Re: How to convert 32bit to 24 bit NSBitmapImageRep
  • Index(es):
    • Date
    • Thread