• 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: 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


  • Follow-Ups:
    • Re: Programatically creating/saving an NSImage;
      • From: Matt Budd (Madentec) <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>)
 >Re: Programatically creating/saving an NSImage; (From: Matt Budd (Madentec) <email@hidden>)
 >Re: Programatically creating/saving an NSImage; (From: Serge Meynard <email@hidden>)
 >Re: Programatically creating/saving an NSImage; (From: Matt Budd (Madentec) <email@hidden>)

  • Prev by Date: can't access menu?
  • Next by Date: Re: Insert new project into source control
  • Previous by thread: Re: Programatically creating/saving an NSImage;
  • Next by thread: Re: Programatically creating/saving an NSImage;
  • Index(es):
    • Date
    • Thread