• 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: compositing a masked image and printing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Prev by Date: Re: [ANN] Shovel - Third-Party "Software Update"
  • Next by Date: Re: Memory management question
  • Previous by thread: compositing a masked image and printing
  • Next by thread: List of User Accounts
  • Index(es):
    • Date
    • Thread