Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bker

macrumors newbie
Original poster
May 22, 2010
6
0
Hi,

I would like to know how can i get information from a CGImageRef image to put them into initWithBitmapDataPlanes like bitsPerSample, hasAlpha, bitsPerPixel etc... ?
Thank you!

PHP:
	NSImage *imagePath = [[NSImage alloc] initWithContentsOfFile:@"/Users/bker/Desktop/TEST/001.jpg"];
	//NSImage *imagePath = [[NSImage alloc] initWithContentsOfFile:@"/Users/bker/Desktop/TEST/001.png"];
	//NSImage *imagePath = [[NSImage alloc] initWithContentsOfFile:@"/Users/bker/Desktop/TEST/001.tiff"];

	CGImageSourceRef asource = CGImageSourceCreateWithData((CFDataRef)[imagePath TIFFRepresentation], NULL);
	CGImageRef bitmap =  CGImageSourceCreateImageAtIndex(asource, 0, NULL);
	
	NSBitmapImageRep *bitmap = [NSBitmapImageRep alloc];
    [bitmap initWithBitmapDataPlanes:NULL
                              pixelsWide: ?
                              pixelsHigh: ?
                           bitsPerSample: ?
                         samplesPerPixel: ?
                                hasAlpha: ?
                                isPlanar: ?
                          colorSpaceName: ?
                            bitmapFormat: ?
                             bytesPerRow: ?
                            bitsPerPixel: ?
	 ];
 
http://developer.apple.com/mac/libr...//apple_ref/doc/uid/TP30000956-CH1g-TPXREF183

But you should instead use -[NSBitmapImageRep initWithCGImage:]

Also your initialization is wrong. You should use this format:

Code:
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes...

EDIT: instead of loading an NSImage, getting its TIFF, loading that TIFF into a CGImageSource, then loading that CGImage into an NSBitmapImageRep, just create the CGImageSource via CGImageSourceCreateWithURL() with the file URL, then use initWithCGImage: to create your NSBitmapImageRep.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.