Re: Programatically creating/saving an NSImage;
Re: Programatically creating/saving an NSImage;
- Subject: Re: Programatically creating/saving an NSImage;
- From: glenn andreas <email@hidden>
- Date: Tue, 22 Mar 2005 10:36:38 -0600
On Mar 22, 2005, at 10:05 AM, Matt Budd (Madentec) wrote:
Hey Serge,
I've tried that but still no success. I get the same solid-black (for
JPG) and solid-white (for TIFF)...here is the modified example:
-----------------------------------------------
float lfWidth = 25;
float lfHeight = 50;
NSImage *loTestImage = [[NSImage alloc] initWithSize:
NSMakeSize(lfWidth, lfHeight)];
[loTestImage lockFocus];
NSBitmapImageRep *loTestImageRep = [[NSBitmapImageRep alloc]
initWithFocusedViewRect: NSMakeRect(0, 0, lfWidth, lfHeight)];
//Here I would do more complicated NSBezierPath stuff
[[NSColor redColor] set];
NSRectFill(NSMakeRect(0, 0, lfWidth, lfHeight));
[loTestImage unlockFocus];
[[loTestImageRep TIFFRepresentation] writeToFile: @"/test.tif"
atomically: YES];
[[loTestImageRep representationUsingType: NSJPEGFileType properties:
nil] writeToFile: @"/test.jpg" atomically: YES];
[loTestImageRep release];
[loTestImage release];
-----------------------------------------------
- Matt
The problem is that you created loTestImageRep _before_ you draw into
the image. initWithFocusedViewRect takes a snapshot of the current
contents of the focused view rect, which, at that point, is blank.
Try moving that line to after your drawing commands (but before the
unlockFocus)
Glenn Andreas email@hidden
<http://www.gandreas.com/> oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
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