Composing an NSImage to print
Composing an NSImage to print
- Subject: Composing an NSImage to print
- From: Olivier Palliere <email@hidden>
- Date: Tue, 11 Jan 2011 16:57:07 +0100
- Priority: normal
Hi Guys,
I'm working on an app for my personal use that needs to print images I drag on an NSImageView to display a thumbnail.
Source images are about 500x500 at 300dpi for most.
When I want to print them, I use this snippet of code from Apple's doc:
frontRect = NSMakeRect(0,0,500, 500);
NSImageView *tempIm = [[NSImageView alloc] initWithFrame:frontRect];
[tempIm setImage:[cusThumbFront image]];
NSData* theData = [tempIm dataWithPDFInsideRect:[tempIm bounds]];
NSPDFImageRep* pdfRep = [NSPDFImageRep imageRepWithData:theData];
// Create a new image to hold the PDF representation.
NSImage* pdfImage = [[NSImage alloc] initWithSize:IMG_SIZE];
[pdfImage addRepresentation:pdfRep];
When I add this image to a NSImageView and give it to a printOperation, it is printed crystal clear with the right resolution.
If I try however, to draw this image in a new one to add my borders like this:
[compositeImage lockFocus];
[pdfRep drawInRect:frontRect fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0];
fpath = [NSBezierPath bezierPathWithRect:frontRect];
[fpath setLineWidth:1];
[[NSColor blackColor] set];
[fpath stroke];
[compositeImage unlockFocus];
(I tried to drawInRect both the PDFImageRep or the NSImage directly with the same failed results)
The resulting image looses the printing resolution and the printed image
is blurry. I read similar posts that explains that
lockFocus/unlockFocus rasterizes the image, and that I should use PDFKit
but the doc on that one is sparse (to me at least). I also found some
post indicating I should use bestRepresentationForDevice but this method
is deprecated in 10.6 which is my target system.
What would be the best way to have my high res picture print with my watermark on it?
I know from my unsuccessful searches for the past weeks that this theme
has been addressed several times but I just can't seem to find an easy
answer to my problem.
Many thanks for your help,
Olivier./.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden