Problem copying pdfImageRep to bitmapRep.
Problem copying pdfImageRep to bitmapRep.
- Subject: Problem copying pdfImageRep to bitmapRep.
- From: Graham Cox <email@hidden>
- Date: Fri, 11 Jul 2008 02:23:57 +1000
OK, it's very late (2.18 am) and I'm almost cross-eyed with fatigue..
but I just can't see what I'm doing wrong here. I want to render pdf
data into a bitmap as part of an export conversion. My pdf data is
good (I can save it as a pdf file and that comes up OK). My bitmap is
good, but it's blank.
- (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 );
// draw the PDF rep into the bitmap rep. To do this, bmrep needs to
be added to an NSImage
NSRect destRect = NSZeroRect;
destRect.size = bmSize;
NSImage* bmImage = [[NSImage alloc] initWithSize:bmSize];
[bmImage addRepresentation:bmRep];
[bmImage lockFocusOnRepresentation:bmRep];
[pdfRep drawInRect:destRect];
[bmImage unlockFocus];
[bmImage removeRepresentation:bmRep];
[bmImage release];
return [bmRep autorelease];
}
tia, off to bed...
Graham
_______________________________________________
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