Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Clearing an NSImage

Clearing an NSImage
Thread Tools
DayLateDon
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Jan 21, 2002, 01:46 AM
 
Hello ...

How do I clear the contents of an NSImage, leaving a blank and transparent canvas for redrawing?

Using NSBezierPath's fillRect: with clearColor (or any color with a zeroed alpha) just coats the image with transparent paint, effectively doing nothing. NSColor's swatchInRect draws the half-white-half-black square.

I _can_ copy in a transparent .tiff or something of that sort, but shouldn't there be a straighforward way to "paint" nothingness in? (Right now I'm interested in knocking out an entire image; but what if I want to "remove" a particular shape within an image by making its pixels transparent?) I can't seem to find an appropriate method.


Thanks ...

DayLateDon
     
Mac Boy
Junior Member
Join Date: Dec 2000
Location: Boston, MA USA
Status: Offline
Reply With Quote
Jan 21, 2002, 03:23 PM
 
Ran across this today in NSGraphics.h:

APPKIT_EXTERN void NSEraseRect(NSRect aRect);

Have you tried this function?

- Ross
     
DayLateDon  (op)
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Jan 21, 2002, 04:16 PM
 
Hello ...

NSEraseRect() just fills a rectangle with white; no transparency.

However, in checking that out, I ran across NSRectFillUsingOperation(NSRect aRect, NSCompositingOperation op). It's a "description forthcoming" function, but using NSCompositeClear for the operation seems to work just fine.


Thanks for the nudge ...

DayLateDon
     
lindberg
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Jan 22, 2002, 01:35 PM
 
Right, the default compositing operation is usually NSCompositeSourceOver, (layering over top) whereas you want to use NSCompositeCopy (replace the pixels with the specified color) or maybe NSCompositeClear as you found.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:36 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,