Re: Bundled Image scaled down when displayed (drawAtPoint)
Re: Bundled Image scaled down when displayed (drawAtPoint)
- Subject: Re: Bundled Image scaled down when displayed (drawAtPoint)
- From: Quincey Morris <email@hidden>
- Date: Sun, 03 Jul 2011 18:55:26 -0700
On Jul 3, 2011, at 09:00, Benjamin Dubois wrote:
> NSString* imageName = [[NSBundle mainBundle]
> pathForResource:@"image1" ofType:@"png"];
> NSLog(@"imageName:%@",imageName);
> NSImage* tempImage = [[NSImage alloc] initWithContentsOfFile:imageName];
It's a whole lot easier to use the following 1 line instead of the above 4:
NSImage* tempImage = [NSImage imageNamed: @"image1"];
You don't even need to specify the file extension.
> // Draw the image in the current context.
>
> [tempImage drawAtPoint:point
> fromRect: NSZeroRect
> operation: NSCompositeSourceOver
> fraction: 1.0];
The NSImage object has property "size" that is the logical size of the image***.
The object also has an array of representations, presumably containing just a single representation of class NSBitmapImageRep. This has "pixelsWide" and "pixelsHigh" properties taken from the input file, with obvious meanings.
If the image's "size" property is {0, 0}, then the size is derived from the representation as {pixelsWide, pixelsHigh}. If the "size" property is anything else, the representation is scaled to this size whenever the image is drawn.
Armed with the above information, you should be able to set a breakpoint (say, at your drawAtPoint:... call), and examine these properties in the debugger to find out why scaling is occurring. (You can log the information, but ... sheesh! ... use the debugger, that's what it's for.)
Note that it's certainly possible that your image editor was itself displaying the image at the wrong size, or that (if you exported from something else to PNG format) metadata was lost or mistranslated.
*** It's the logical size in points (1/72 inch), but these may be logical points, not real points. NSWindow can have a scale factor that translates logical points into screen pixels, and the dpi resolution that Mac OS thinks is your monitor resolution might be a lie. So, if you display a 72 x 72 point image and measure the result onscreen, it may not be an inch square. But NSImage tried its best!
_______________________________________________
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