Re: Programatically creating/saving an NSImage;
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