Re: compositing a masked image and printing
Re: compositing a masked image and printing
- Subject: Re: compositing a masked image and printing
- From: Paul FitzGerald <email@hidden>
- Date: Wed, 24 Mar 2004 13:50:20 -0800
Yup.
I've been asking the same question and haven't gotten any response from
the list.
The best I can figure is that compositing does not work when drawing in
a printing context. Sounds like a bug.
What I an doing is compositing into a temp NSImage then printing that
image. I do this within my drawRect method.
Here is a snippet of my drawRect. If you see any problems in it please
let me know. Note I've stripped out some math on rectangles to make it
easier to read so some of the rects may not be right.
- (void)drawRect:(NSRect)rect
{
float aFraction = 1.0;
if([[NSGraphicsContext currentContext] isDrawingToScreen]) {
NSRect sourceRect = NSMakeRect(0,0,[[userImage image]
size].width,[[userImage image] size].height);
[[userImage image] drawInRect:destRect
fromRect:NSMakeRect(0,0,[[userImage image]
size].width,[[userImage image] size].height)
operation: NSCompositeCopy
fraction: aFraction];
[[maskImage image] drawInRect:rect
fromRect:NSMakeRect(0,0,[[maskImage image]
size].width,[[maskImage image] size].height)
operation: NSCompositePlusLighter
fraction: aFraction];
} else {
// In this case I start by copying the user image.
NSImage* extraImage = [[userImage image] copyWithZone:nil];
if (extraImage) {
NSSize userImageFullSize = [[userImage image] size];
NSRect maskSourceRect = NSMakeRect(0.0,0.0,[[maskImage image]
size].width,[[maskImage image] size].height);
[extraImage setSize: userImageFullSize];
[extraImage lockFocusOnRepresentation:bestRep];
if (maskImage)
[[maskImage image] drawInRect:maskDestRect
fromRect:maskSourceRect
operation: NSCompositePlusLighter
fraction: aFraction];
[extraImage unlockFocus];
/// Now draw to the printer.
[extraImage drawInRect:rect fromRect:sourceRect operation:
NSCompositeCopy fraction: aFraction];
[extraImage release];
}
#endif
}
}
This is not the best solution but it seems to work.
Paul FitzGerald
On Mar 23, 2004, at 9:21 PM, email@hidden wrote:
>
I'm having trouble compositing an NSImage object with a custom mask
>
image. My code works like a charm when drawing on screen, but fails
>
when printed out on paper. The mask is not applied when printed,
>
instead I get the whole picture.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.