On Jan 15, 2016, at 03:42 , Andreas Höschler <ahoe...@smartsoft.de> wrote:
> 
> It seems I have a lack of understanding of the difference of points and 
> pixels.

With “retina” displays, there can be 2 or 3 pixels for each unit of the drawing 
coordinate system (points). When you did this:

>       NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] 
> initWithFocusedViewRect:[mapView bounds]];

the bound rect is in view coordinates (points), but what you get back is 
actually an array of pixels.

> But how does NSBitmapImageRep know which pixel resolution to choose? How does 
> it derive Pixels=1702x1798  when I create the imageRep with a {{0, 0}, {851, 
> 899} rect?

It doesn’t choose. The view/window has a backing store at a pixel resolution 
that depends on the display device. The image capture API simply grabs all of 
the pixels inside the 851 x 899 (points) rect, and this happens to be 1792 x 
1798 pixels. Yes, the number of pixels you get back will vary according to 
which Mac you run this on.

>             NSImage *image = [[NSImage alloc] initWithData:imageData];

When you create the image, the PNG imageData (I assume) contains the logical 
(points) bounds of the image you captured, as well as all the actual pixels. As 
a result, the underlying bitmap image rep has 1792 x 1798 pixels, and the image 
itself has size {851 x 899}.

This is normally what you want to happen. An image whose point size is 851 x 
899 will draw as 851 x 899 points on any device. (The physical size of a point 
may vary between displays, but that’s a different issue.) The image drawing API 
has an algorithm for choosing an image rep (from the possibly multiple reps 
within an image object) and a scaling mechanism.

Thus, if you display the image on the same Mac where you captured it, you’ll 
get the same pixels displayed as you captured. If you display it on a 
non-retina Mac (1 pixel per point), the image will be downscaled to 851 x 899 
pixels.

Most of this works transparently behind the scenes. However, NSImage ‘size’ 
property doesn’t always get set automatically to the correct *points* value — 
depending on how you create the image rep, it might get set to the pixel 
dimensions, which makes the NSImage size too big. In such cases, you need to 
set the size property yourself.

_______________________________________________

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

This email sent to arch...@mail-archive.com

Reply via email to