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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to