Re: filling NSImage with binary data from NSData
Re: filling NSImage with binary data from NSData
- Subject: Re: filling NSImage with binary data from NSData
- From: John Stiles <email@hidden>
- Date: Sun, 07 May 2006 21:10:18 -0700
Lester Dowling wrote:
On 08/05/2006, at 1:24 PM, marc joanisse wrote:
Here's the code so far. It works once but fails when called a second
time.
- (void)drawXImage:(int)xSlice
{
NSBitmapImageRep* imageRep;
unsigned char *plane;
int i,j;
imageRep=[[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
pixelsWide:256
pixelsHigh:256
bitsPerSample:8
samplesPerPixel:1
hasAlpha:NO
isPlanar:YES
colorSpaceName:NSCalibratedWhiteColorSpace
bytesPerRow:256
bitsPerPixel:0]
autorelease];
NSImage* producedNSImage = [[[NSImage alloc]
initWithSize:NSMakeSize(256, 256)] autorelease];
[producedNSImage addRepresentation:imageRep];
// pointer to the bitmapData
unsigned char *data = [imageRep bitmapData];
// pointer to the portion of vmrData (an NSData object) I want
to show
// ***segfault happens here!***
The seg fault happens because the image is not planar. Substitute
"isPlanar:NO" because according to the manual:
• The isPlanar argument should be YES if the data components
are laid out in a series of separate “planes” or channels (“planar
configuration”) and NO if component values are interwoven in a single
channel (“meshed configuration”).
Since you have a grayscale image, there is only a single channel.
I would think that a grayscale image could be considered either planar
or non-planar.
_______________________________________________
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