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: Tue, 22 Mar 2005 09:05:22 -0700
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
On Mar 21, 2005, at 5:20 PM, Serge Meynard wrote:
Try
[theImage lockFocus];
// Draw some stuff...
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc]
initWithFocusedViewRect:someRect];
[theImage unlockFocus];
// Manipulate the bitmap etc...
Serge
On Mar 21, 2005, at 17:51, Matt Budd (Madentec) wrote:
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
_______________________________________________
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