• 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: Troubles with NSView...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Troubles with NSView...


  • Subject: Re: Troubles with NSView...
  • From: Phillip Hutchings <email@hidden>
  • Date: Tue, 3 Feb 2004 10:55:09 +1300

On 3/02/2004, at 12:20 AM, Daniele wrote:

[...]

- (void) myMethod {
toDraw = [[NSImage imageNamed: thRead] retain];

mapView = [[NSView alloc] initWithFrame: NSMakeRect(0,0,800,600)]
[toDraw lockFocus];
[mapView drawRect: NSMakeRect(10,10,16,16)]; // 16x16 pict
[toDraw unlockFocus];

// export it
NSData *d = [[NSData alloc] initWithData: [mapView dataWithPDFInsideRect: NSMakeRect(0,0,800,600)]];
[d writeToFile: @"test.pdf" atomically: YES];
[d release];
}

the output file is a 4kb PDF with nothing.... where is the mistake?

You're not drawing anything, other than a 16x16 white rectangle, hence you're not going to have any output. I'm assuming you want to put the NSImage at 10,10, sized to 16x16 pixels. So here's how:

- (void) myMethod {
toDraw = [[NSImage imageNamed: thRead] retain];
// Resize the image, make sure it's 16x16
[toDraw setScalesWhenResized: YES]; // We want to scale the image, not crop it
[toDraw lockFocus]; // Needs to be the current graphics context
[[NSGraphicsContext currentContext] setImageInterpolation: NSImageInterpolationHigh]; // Slower, but higher quality. Not very slow really.
[toDraw setSize:NSMakeSize(16,16)]; // Size to 16x16
[toDraw unlockFocus]; //Unlock our focus

mapView = [[NSView alloc] initWithFrame: NSMakeRect(0,0,800,600)]
[toDraw lockFocus];
[toDraw compositeToPoint:NSMakePoint(10,10) operation:NSCompositeCopy]; // Draw at 10,10 Size is 16,16.
[toDraw unlockFocus];

// export it
NSData *d = [[NSData alloc] initWithData: [mapView dataWithPDFInsideRect: NSMakeRect(0,0,800,600)]];
[d writeToFile: @"test.pdf" atomically: YES];
[d release];
}


Also, remember that NSView's that aren't flipped (see the docs for how to change it) measure from the bottom left corner of the view.

--
Phillip Hutchings
email@hidden
http://www.sitharus.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Troubles with NSView... (From: Daniele <email@hidden>)

  • Prev by Date: Re: Cocoa/Windows parallel dvlpmt
  • Next by Date: Re: constants? strings? what do i wrong?
  • Previous by thread: Troubles with NSView...
  • Next by thread: Looking for two (2) freelance Cocoa developers
  • Index(es):
    • Date
    • Thread