• 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: Problem converting pdfs to jpegs with Cocoa & Quartz...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Problem converting pdfs to jpegs with Cocoa & Quartz... (From: Michael Heinz <email@hidden>)
 >Re: Problem converting pdfs to jpegs with Cocoa & Quartz... (From: Sven Hoffmann <email@hidden>)
 >Re: Problem converting pdfs to jpegs with Cocoa & Quartz... (From: Michael Heinz <email@hidden>)

  • Prev by Date: Re: plain text and Spotlight
  • Next by Date: Re: One window for all documents.
  • Previous by thread: Re: Problem converting pdfs to jpegs with Cocoa & Quartz...
  • Next by thread: Re: Problem converting pdfs to jpegs with Cocoa & Quartz...
  • Index(es):
    • Date
    • Thread