Re: Problem converting pdfs to jpegs with Cocoa & Quartz...
Re: Problem converting pdfs to jpegs with Cocoa & Quartz...
- Subject: Re: Problem converting pdfs to jpegs with Cocoa & Quartz...
- From: Michael Heinz <email@hidden>
- Date: Tue, 10 May 2005 08:07:22 -0400
Doh!
I was resizing the wrong rectangle! The blurriness was because I was only resizing the destination, not the source!
Thanks for taking the time to do the sample code, it was a big help. In case anyone else is interested in this, I *did* have to change the code somewhat to properly render in an off-screen mode: first, the original code created an image with a NSCachedImageRep inside, which cannot be converted to a jpeg or tiff, so I had to create the NSBitmapImageRep via initWithFocusedViewRect. Second, it was necessary to fill the destination image with a white rectangle, then draw the PDF on top of it. Otherwise I ended up with jpegs that had black text drawn on a black background - not helpful at all.
NSImage *image = [[[NSImage alloc] initWithSize:bmpSize] autorelease];
NSRect bmpRect = NSMakeRect(0.0,0.0,bmpSize.width,bmpSize.height);
[image setScalesWhenResized:YES];
[image setSize:bmpSize];
[document setScalesWhenResized:YES];
[document setSize:bmpSize];
[image lockFocus];
NSBezierPath *bp = [NSBezierPath bezierPathWithRect:bmpRect];
[[NSColor whiteColor] set];
[bp fill];
[document drawInRect:bmpRect
fromRect:bmpRect
operation:NSCompositeSourceOver
fraction:1.0];
NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:bmpRect] autorelease];
[image unlockFocus];
NSData *jpeg = [bitmap representationUsingType:NSJPEGFileType properties:dict];
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden