I just noticed that the program I use to create Png files creates files with 
twice the number of pixels in each dimension.
Obviously because since I last used it, I have switched to a Retina Mac Book.

Ok, so I have to fix this program.

But: how do I detect that the programm is running on a computer where each 
pixel is really four pixels?
Both NSScreen and NSWindow have a backingScaleFactor property, which seems to 
be right.

But my code does neither involves a screen nor a window:

finalWidth = 50;        because I want a Png 50 pixels wide
finalWidth /= 2;        ← this fixes my Retina problem, but hardcoding this 
looks simply wrong
CGFloat scaleFactor = finalWidth / bounds.size.width;
NSSize sizE = NSMakeSize( finalWidth, bounds.size.height * scaleFactor );
NSImage *image = [[NSImage alloc] initWithSize: sizE];
[image setFlipped:YES];
[image lockFocus];
NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
NSAffineTransform *transform = [NSAffineTransform transform];
[transform scaleXBy: scaleFactor  yBy: scaleFactor ];
[transform translateXBy: -bounds.origin.x  yBy: -bounds.origin.y ];
[transform concat];

... do some drawing

[image unlockFocus];
NSRect recct = NSMakeRect(0, 0, sizE.width, sizE.height );       
[image lockFocus];
NSBitmapImageRep *bitmapImageRep = [[NSBitmapImageRep alloc] 
initWithFocusedViewRect: recct ];
[image unlockFocus];
NSData *data = [ bitmapImageRep representationUsingType: NSPNGFileType  
properties: nil ];

... write data to file

So where do I get my backingScaleFactor from?
What if there are two screens, one Retina, one not?

Kind regards,

Gerriet.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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

This email sent to [email protected]

Reply via email to