Re: NSImage and 8 bit
Re: NSImage and 8 bit
- Subject: Re: NSImage and 8 bit
- From: "Robert W. Kuhn" <email@hidden>
- Date: Tue, 30 Nov 2004 09:26:16 +0100
On 29.11.2004 20:13 Uhr +0000 Marcel Weiher wrote:
> Try using NSBitmapImageRep directly, the code you are using may or may
> not do what you're thinking.
Thank you for your help. I discovered that I have to use
initWithBitmapDataPlanes:
pixelsWide:
pixelsHigh:
bitsPerSample:
samplesPerPixel:
hasAlpha:
isPlanar:
colorSpaceName:
bytesPerRow:
bitsPerPixel:
My code now looks like that:
mLeftImg = [NSImage alloc];
[mLeftImg setDataRetained:YES];
[mLeftImg
initWithContentsOfFile:@"/Users/rkuhn/Programmierung/Disparity/A_000_000.bmp"];
NSLog(@"BPP: %i", [mLeftImg bitsPerPixel]);
NSBitmapImageRep *bmpRep;
NSData *dat;
dat = [NSData dataWithContentsOfFile:
@"/Users/rkuhn/Programmierung/Disparity/A_000_000.bmp" ];
bmpRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned
char **)&dat
pixelsWide:[mLeftImg width]
pixelsHigh:[mLeftImg height]
bitsPerSample:8
samplesPerPixel:1
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSDeviceWhiteColorSpace
bytesPerRow:[mLeftImg width]*1//pixelsWide*samplesPerPixel
bitsPerPixel:8//bitsPerSample*samplesPerPixel];
NSLog(@"BPP: %i", [bmpRep bitsPerPixel]);
The Log:
2004-11-30 09:22:32.383 Disparity[1513] BPP: 32
2004-11-30 09:22:32.390 Disparity[1513] BPP: 8
Ugly code. Not very handy to load first the image (to get width and
height)
and the the data again.
> This is probably a cached representation, so you are getting the depth
> of the bitmap cache. The last time I checked NSImage discards the
> original data unless you tell it to -setDataRetained:YES.
I also did try this. I always get only 32bit-Data. Also the NSImage has
always only one NSBitmaprepresentation - the 32bit data.
Mit freundlichen Grüßen
Robert W. Kuhn
_______________________________________________
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