Save tiff with no alpha
Save tiff with no alpha
- Subject: Save tiff with no alpha
- From: Ben Mackin <email@hidden>
- Date: Sun, 10 Nov 2002 18:52:04 -0800
What I want to do is save a tiff with no alpha channel. I was told the
following:
>
It's sort of involved, but you could get an NSBitmapImageRep from your image,
>
create a new NSBitmapImageRep with the same parameters (except three samples
>
per pixel instead of four, and alpha NO), and then copy the data in. As long
>
as you have bitsPerPixel set to 32, it'll just ignore the alpha data.
So I did the following:
data = [image1 TIFFRepresentation];
NSBitmapImageRep *srcImageRep = [[[NSBitmapImageRep alloc]
initWith
Data:data] autorelease];
NSBitmapImageRep *destImageRep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:[srcImageRep pixelsWide]
pixelsHigh:[srcImageRep pixelsHigh]
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:NULL
bitsPerPixel:32] autorelease];
const int srcBytesPerPlane = [srcImageRep bytesPerPlane];
const int destBytesPerPlane = [destImageRep bytesPerPlane];
NSParameterAssert( srcBytesPerPlane == destBytesPerPlane );
unsigned char *srcBuffer = [srcImageRep bitmapData];
unsigned char *destBuffer = [destImageRep bitmapData];
memmove(destBuffer, srcBuffer, destBytesPerPlane);
Ok using this code, I get an interesting result. The file comes up as a
black image (the whole page is black). That is not what I want, so something
is not going good.
Is this the correct way of doing this? Is there an easier way?
Thanks,
Ben
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.