• 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: NSImage -- getting raw bitmap data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage -- getting raw bitmap data


  • Subject: Re: NSImage -- getting raw bitmap data
  • From: "Dennis C.De Mars" <email@hidden>
  • Date: Sat, 2 Aug 2003 10:32:44 -0700

Yes, the documentation on images seems to be terse in several respects.

The key to getting the raw pixel data on an image seems to be -TIFFRepresentation (which, despite its name, returns an NSData object, not an NSImageRep object). I think the most direct way to create a bitmap from an image is probably:

NSData* tiffData = [theImage TIFFRepresentation];
NSBitmapImageRep* bitMapRep = [NSBitmapImageRep imageRepWithData:tiffData];

(Assuming imageRepWithData: accepts data in TIFF format; this is one of those areas where the documentation is terse but I'm 99% sure this will work).

This doesn't totally address your problem because it doesn't let you force the depth, etc., all of that is predetermined in the TIFF representation. NSImageRep has some interesting methods for setting these parameters but I don't know if using them on a bitmap rep will cause any kind of conversion to take place. You could experiment.

Of course, since you have the raw pixels at this point you could do any conversion of depth, colorspace, etc. by brute force, but it obviously would be a lot more convenient if you could get Cocoa to do it for you. I guess I would have tried to do it the way you tried (drawing the image into a preformed bitmapimagerep). Don't know why that didn't work, but if you could post some code maybe we could suggest modifications.

- Dennis D.

On Saturday, August 2, 2003, at 07:49 AM, Uli Kusterer wrote:

Hi,

I'm using NSBitmapImageRep's initWithBitmapDataPlanes: to get some raw bitmap data into an NSImageView. Now, I've set this view to be editable, and users can drag image files onto it to replace the data.

But how do I get the raw image data from whatever image the user dragged onto my NSImageView? Basically, I'd need the reverse operation of initWithBitmapDataPlanes:, but I need to force the image to be a particular depth, number of planes etc.

Apple's "Drawing Images" docs are pretty terse on that topic, and Mamasam only brought up a sample by Marco Binder that was close but no cookie, even less on cocoadevcentral. I also tried to lockFocus on the NSBitmapImageRep and just draw the image in there, but that didn't change the data I passed in.

Help?

Thanks for any hints and clues,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSImage -- getting raw bitmap data
      • From: "M. Uli Kusterer" <email@hidden>
References: 
 >NSImage -- getting raw bitmap data (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: Corrupted NSMutableString
  • Next by Date: Leroy the Llama
  • Previous by thread: NSImage -- getting raw bitmap data
  • Next by thread: Re: NSImage -- getting raw bitmap data
  • Index(es):
    • Date
    • Thread