PDA

View Full Version : NSImage and C data...


Mars_999
2004.08.15, 09:22 PM
I am trying to send my unsigned char* data to NSImage so I can use NSImageView to show the image on screen. I am not having luck passing my C data to the NSData class? or NSImage class.


NSData *image = [NSData dataWithBytes:texture.imageData length:sizeof(texture.imageWidth * texture.imageHeight * texture.colorMode)];
NSImage *beforeBlendmap = [[NSImage alloc] initWithData:texture.imageData];


Thanks

anarchie
2004.08.15, 11:04 PM
It seems like you have raw bitmap data there. [[NSImage alloc] initWithData:] expects its data in a known file format such as JPEG. Try using this method (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSBitmapImageRep.html#//apple_ref/doc/uid/20000347/initWithBitmapDataPlanesCOLONpixelsWideCOLONpixels HighCOLONbitsPerSampleCOLONsamplesPerPixelCOLONhas AlphaCOLONisPlanarCOLONcolorSpaceNameCOLONbytesPer RowCOLONbitsPerPixelCOLON) to create an NSBitmapImageRep, then create an empty NSImage with [[NSImage alloc] init] and add the NSBitmapImageRep to it using addRepresentation: