• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: filling NSImage with binary data from NSData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: filling NSImage with binary data from NSData


  • Subject: Re: filling NSImage with binary data from NSData
  • From: "Greg Herlihy" <email@hidden>
  • Date: Sun, 7 May 2006 14:56:30 -0700

One major problem is that the plane parameter has to be a pointer an array of pointers to the image data - and not a pointer to the image data itself. Each pointer in this array points to a different plane of the image. But being a grayscale image, there should be only one pointer present in this array.

Alternately, the program could pass NULL for the plane parameter. In that case the NSBitmageImageRep object would allocate enough memory to hold the image data based on the image's other measurements. The program would then copy the image data into the address returned by calling bitmapData on the bitmap image rep object.

Greg

----- Original Message ----- From: "marc joanisse" <email@hidden>
To: <email@hidden>
Sent: Sunday, May 07, 2006 12:37 PM
Subject: filling NSImage with binary data from NSData



Hi, I'm working on a cocoa app that visualizes part of a 3D dataset (MRI images) as a discrete 2D "slice". I am using NSImage to show the image. The user chooses a slice of the array (a 256 x 256 grid) to show in an NSImageView.

The hard part here is the data file format, which is a binary file
consisting of an 8-bit header followed by a 256*256*256 array of
bytes. Each byte specifies a grayscale value.

I have hucked together some code based on other postings and replies
on this list, but I've hit a dead end. Here's where I am at:

I load this data file into an NSData object (declared with global
scope)  as follows

     vmrData = [NSData dataWithContentsOfFile:fileName];

From what I can tell, this seems to do the right thing.

Then I trigger the following procedure that actually loads the desired portion of the data into the NSImage using an NSBitmapImageRep:

- (void)drawXImage:(int)xSlice
{
  NSBitmapImageRep* imageRep;
  // a pointer to the portion of vmrData containing the desired slice
  unsigned char *plane;

  // pointer to the part of the dataset we want to visualize
  // note vmrData has global scope
   plane = (unsigned char*)[vmrData bytes]+8+(256 * 256 * xSlice);

  // init the NSBitmapImageRep
  imageRep=[[[NSBitmapImageRep alloc]
                             initWithBitmapDataPlanes:&plane
                                                        pixelsWide:256
                                                        pixelsHigh:256
                                                     bitsPerSample:8
                                                   samplesPerPixel:1
                                                          hasAlpha:NO
                                                          isPlanar:YES
                                   colorSpaceName:NSCalibratedWhiteColorSpace
                                                       bytesPerRow:0
                     bitsPerPixel:0] autorelease];

  // create an NSImage and show it in the window
  //n.b. imageView is my delegate for the NSImageView  I want to
  // show the image in.
  NSImage *producedNSImage;
  producedNSImage = [NSImage alloc];
  [producedNSImage addRepresentation:imageRep];
  [imageView setImage:producedNSImage];

}

The procedure produces a segfault when I run it, but not till after it
returns.  I suspect the problem ahs to do with how I am setting the
"plane" pointer or how I'm telling the NSBitmapImageRep about it.

As a sidenote: I am also unclear whether I should be releasing
producedNSImage and imageRep at the end of the procedure, or whether
the view needs this to be retained.

Thanks for whatever help you can give me on this,

-Marc-

--
Marc Joanisse
"... and such small quantities."
_______________________________________________
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 

_______________________________________________
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


  • Follow-Ups:
    • Re: filling NSImage with binary data from NSData
      • From: "marc joanisse" <email@hidden>
    • Re: filling NSImage with binary data from NSData
      • From: Uli Kusterer <email@hidden>
References: 
 >filling NSImage with binary data from NSData (From: "marc joanisse" <email@hidden>)

  • Prev by Date: Re: filling NSImage with binary data from NSData
  • Next by Date: Re: object type testing
  • Previous by thread: Re: filling NSImage with binary data from NSData
  • Next by thread: Re: filling NSImage with binary data from NSData
  • Index(es):
    • Date
    • Thread