PDA

View Full Version : Making a totally black NSImage object




foidulus
Nov 3, 2008, 05:25 AM
is it possible? I want to insert some black spots in between QTMovie objects and insertEmptySegmentAt just keeps the last frame played showing for the programmed duration. I want to just insert some black, but it looks like I have to make an NSImage object to do it. I guess I could just whip up a quick all black image and load that, but I would rather do it programatically.

Any suggestions would be appreciated.



robbieduncan
Nov 3, 2008, 05:32 AM
Create an NSImage, lock focus on it and draw the rectangle of pure black then unlock focus?

Look at the lockFocus (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSImage_Class/Reference/Reference.html#//apple_ref/occ/instm/NSImage/lockFocus) method of NSImage (and the unlockFocus (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSImage_Class/Reference/Reference.html#//apple_ref/occ/instm/NSImage/unlockFocus) method too), the set (http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSColor_Class/Reference/Reference.html#//apple_ref/occ/instm/NSColor/set) method of NSColor and finally the fillRect: (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/Reference/Reference.html#//apple_ref/occ/clm/NSBezierPath/fillRect:) method of NSBezierPath.

foidulus
Nov 3, 2008, 09:28 AM
Create an NSImage, lock focus on it and draw the rectangle of pure black then unlock focus?

Look at the lockFocus (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSImage_Class/Reference/Reference.html#//apple_ref/occ/instm/NSImage/lockFocus) method of NSImage (and the unlockFocus (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSImage_Class/Reference/Reference.html#//apple_ref/occ/instm/NSImage/unlockFocus) method too), the set (http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSColor_Class/Reference/Reference.html#//apple_ref/occ/instm/NSColor/set) method of NSColor and finally the fillRect: (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/Reference/Reference.html#//apple_ref/occ/clm/NSBezierPath/fillRect:) method of NSBezierPath.

Thanks, but that looks like you won't be able to do that while running "headless"...

I think I'll just go with the black jpeg.

kainjow
Nov 3, 2008, 11:37 AM
Just make sure you call NSApplicationLoad() if you haven't already, and it'll work fine.