• 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: Programatically creating/saving an NSImage;
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programatically creating/saving an NSImage;


  • Subject: Re: Programatically creating/saving an NSImage;
  • From: Matt Budd (Madentec) <email@hidden>
  • Date: Mon, 21 Mar 2005 15:51:46 -0700

Hi Ricky,

I need to create a NSBitmapImageRep, because I want to manipulate the pixels of the image before I save. In other words, I want to draw using an NSBezierPath into an NSImage, and then manipulate that image's pixels, and then save that image to disk. These secondary manipulations must be done at the pixel level and can't be done at the NSBezierPath level.

If I don't create the NSBitmapImageRep, the NSImage only has 1 representation, a NSCachedImageRep, of which I can get its pixel info (through a -bitmapData message or something similar). If I use -bestRepresentationForDevice:, it returns the only representation, that NSCachedImageRep.

 - Matt


On Mar 21, 2005, at 3:38 PM, Ricky Sharp wrote:

On Mar 21, 2005, at 4:31 PM, Matt Budd (Madentec) wrote:

Thanks for the reply. I tried substituting that call to -lockFocus with this code:

	[loTestImage lockFocusOnRepresentation: loTestImageRep];

But still no luck. It now appears that the random bytes/pixels are going, but for the JPG, I only get a solid-black image, and for the TIFF, it is all white. In neither of them do I get the red background.

And if I try to do more complicated drawing besides just filling a rect (i.e. by using a NSBezierPath and -fill for a custom path), that doesn't show up either....it's still either black or white filled...

Now that I look at it a second time, is there any specific reason for creating the bitmap rep manually in the first place?


What you could do instead is something like this:

create an NSImage with your size
call lockFocus on the image
draw
call unlockFocus on the image
call bestRepresentationForDevice: on the image
with the rep you get back, get other reps (TIFF, JPG) and save them.

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com


_______________________________________________ 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: Programatically creating/saving an NSImage;
      • From: Serge Meynard <email@hidden>
    • Re: Programatically creating/saving an NSImage;
      • From: Shawn Erickson <email@hidden>
References: 
 >Programatically creating/saving an NSImage; (From: Matt Budd (Madentec) <email@hidden>)
 >Re: Programatically creating/saving an NSImage; (From: Ricky Sharp <email@hidden>)
 >Re: Programatically creating/saving an NSImage; (From: Matt Budd (Madentec) <email@hidden>)
 >Re: Programatically creating/saving an NSImage; (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Re: Programatically creating/saving an NSImage;
  • Next by Date: NSTabView won't switch in Jaguar
  • Previous by thread: Re: Programatically creating/saving an NSImage;
  • Next by thread: Re: Programatically creating/saving an NSImage;
  • Index(es):
    • Date
    • Thread