• 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 copying pdfImageRep to bitmapRep. [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem copying pdfImageRep to bitmapRep. [SOLVED]


  • Subject: Re: Problem copying pdfImageRep to bitmapRep. [SOLVED]
  • From: Graham Cox <email@hidden>
  • Date: Fri, 11 Jul 2008 11:13:42 +1000

Thanks Heinrich, that was the key to it. (Sometimes it pays to quit and sleep rather than try and solve "one more thing" before closing down ;-)

Working well now - I adapted my code as follows:



- (NSBitmapImageRep*) bitmapWithResolution:(int) dpi
{
NSPDFImageRep* pdfRep = [NSPDFImageRep imageRepWithData:[self pdf]];

NSAssert( pdfRep != nil, @"couldn't create pdf image rep");

// create a bitmap rep of the requisite size.

NSSize bmSize = [self drawingSize];

bmSize.width = ceil(( bmSize.width * (float)dpi ) / 72.0f );
bmSize.height = ceil(( bmSize.height * (float)dpi ) / 72.0f );

NSBitmapImageRep* bmRep;

bmRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:bmSize.width
pixelsHigh:bmSize.height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:0
bitsPerPixel:0];

NSAssert( bmRep != nil, @"couldn't create bitmap for export");

NSLog(@"size = %@, dpi = %d, rep = %@", NSStringFromSize( bmSize ), dpi, bmRep );

NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithBitmapImageRep:bmRep];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:context];

// draw the PDF rep into the bitmap rep.

NSRect destRect = NSZeroRect;
destRect.size = bmSize;

[pdfRep drawInRect:destRect];

[NSGraphicsContext restoreGraphicsState];

return [bmRep autorelease];
}



thanks again,

Graham


On 11 Jul 2008, at 6:35 am, Heinrich Giesen wrote:

You say: "but I did a lockFocusOnRepresentation:bmRep" and expect that
drawing goes into the bmRep. This is a big but common misunderstanding.
A drawing (within a lockFocus --- unlockFocus) never changes/ overwrites
an NSImageRep contained in the NSImage. With lockFocus you cannnot
draw/write into an NSBitmapImageRep.

_______________________________________________

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


References: 
 >Re: Problem copying pdfImageRep to bitmapRep. (From: Heinrich Giesen <email@hidden>)

  • Prev by Date: Re: Storing structured data in file - any easy way?
  • Next by Date: JDBC Frameworks?
  • Previous by thread: Re: Problem copying pdfImageRep to bitmapRep.
  • Next by thread: XCode3 for Persistent Data on Tiger
  • Index(es):
    • Date
    • Thread