• 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: "marc joanisse" <email@hidden>
  • Date: Sun, 7 May 2006 23:24:18 -0400

Hi,
On 5/7/06, Greg Herlihy <email@hidden> wrote:
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.

Aha! Yes, this does work well (sort of) - I can copy the bytes I want to the pointer to bitmapData and it draws it perfectly. *Except*: when I call the procedure a second time, (e.g., to set a different xSlice, thus changing the data to be displayed) it segfaults.

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!***
	plane = (unsigned char*) [vmrData bytes]+8+(256*256*xSlice);

       // copy bytes from *data to *plane
	for (i=0;i<256;i++){
		for (j=0;j<256;j++){
			*data++=*plane++;
		}
	}

	[imageView setImage:producedNSImage];
}

Any hints are appreciated.

--
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


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

  • Prev by Date: Application for Specific Processors
  • Next by Date: Re: filling NSImage with binary data from NSData
  • 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