Compositing Images to Print
Compositing Images to Print
- Subject: Compositing Images to Print
- From: Paul FitzGerald <email@hidden>
- Date: Fri, 19 Mar 2004 20:47:53 -0800
In my application I have three bitmap NSImages that I am compositing in a
custom view (subclass of NSImageView). My subclass has pointers to the three
NSImages and draws something like...
[image1 drawInRect:destRect fromRect:sourceRect operation:
NSCompositeCopy fraction: 1.0];
[image2 drawInRect:destRect fromRect:sourceRect operation:
NSCompositePlusLighter fraction: 1.0];
[image3 drawInRect:destRect fromRect:sourceRect operation:
NSCompositeSourceAtop fraction: 1.0];
This works fine when drawing to the screen but when printing I'm finding
that does NSCompositePlusLighter not work.
To get around this issue I have added code to check if I am drawing to the
screen and if not I want to composite my image into another NSImage and then
draw that one to the print context. I have code something like this...
- (void)drawRect:(NSRect)rect
{
float aFraction = 1.0;
if([[NSGraphicsContext currentContext] isDrawingToScreen]) {
} else {
// Assume we are printing.
NSImage* tempImage = [image1 copyWithZone:nil];
if (tempImage) {
[tempImage lockFocusOnRepresentation:[tempImage
bestRepresentationForDevice:nil]];
if (image2 )
[self drawIntoDestRect:sourceRect from:image2
withOperator:NSCompositePlusLighter andPreserveAspect: NO];
if (image3 )
[self drawIntoDestRect:sourceRect from:image3
withOperator:NSCompositeSourceAtop andPreserveAspect: NO];
[tempImage unlockFocus];
[tempImage drawInRect:rect fromRect:sourceRect operation:
NSCompositeCopy fraction: aFraction];
}
}
}
Well, this does not work either. What I get is just image1 printed.
So...I guess what I need to ask is Is this the correct way to composite
images together into another NSImage?
Is there some oddity associated with the print graphics context that is
preventing me from doing what I want?
There seems to be very little information on printing from Cocoa. The only
example code I can find is Sketch and it doesn't deal with bitmap images.
It looks like the NSImage compositing is just broken in relation to
printing. Has anyone else found this to be true?
Well, I've spent several days on this already so if anyone can provide input
or a source for sample code I would much appreciate it.
Thanks,
Paul FitzGerald
.
_______________________________________________
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.