Re: Problem copying pdfImageRep to bitmapRep. [SOLVED]
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