Hi Quincey,

thanks a lot for your response. Please read below ...

>> This should in a view with size {851, 899} get me a purple line starting 
>> close to the lower left corner and ending close to the top right corner. But 
>> that's not the case. The picture is drawn zoomed in!??
> 
> I’m not sure I understand completely. The image is drawn “zoomed in”, or the 
> purple rectangle is drawn “zoomed in”, or both?

> 
> Note that the NSBitmapImageRep has dimensions in pixels, The rectangle’s 
> coordinates are in points. You don’t show any code that’s drawing the image 
> back to the screen (if that’s what you’re doing), but NSImage dimensions (the 
> ‘size’ property) is also in points, not pixels, even when the bitmap image 
> rep is in pixels.

It seems I have a lack of understanding of the difference of points and pixels. 
What you describe is/was exactly the problem. My code 

      [mapView lockFocus];
      NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] 
initWithFocusedViewRect:[mapView bounds]];
      NSData *data = [[[rep representationUsingType:NSPNGFileType 
properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] 
forKey:@"NSImageInterlaced"]] retain] autorelease];
      [mapView unlockFocus];

with mapView bounds

2016-01-15 12:27:05.173 ESMMapServer[49673:451971] bounds {{0, 0}, {851, 899}}

generates the following an image with Size={851, 899} and Pixels=1702x1798. 
When I put this into an imageView with 

            NSImage *image = [[NSImage alloc] initWithData:imageData];
            NSLog(@"image %@", image, NSStringFromSize([image size]));
            NSLog(@"mapView %@ frame %@", mapView, NSStringFromRect([mapView 
frame]));
            NSLog(@"mapView %@ bounds %@", mapView, NSStringFromRect([mapView 
bounds]));
            [imageData writeToFile:@"/Users/ahoesch/B.png" atomically:YES]; // 
<--- remove this line
            [mapView setImageScaling:NSScaleNone];
            [mapView setImage:image];            

I of course get the unwanted effect:

    "NSBitmapImageRep 0x7c024280 Size={851, 899} ColorSpace=(not yet loaded) 
BPS=8 BPP=(not yet loaded) Pixels=1702x1798 Alpha=YES Planar=NO Format=(not yet 
loaded) CurrentBacking=nil (faulting) CGImageSource=0x7c015c90"
)>
15/01/16 12:27:05,523 SOSmartBrowser[49595]: mapView <FBMapView: 0x81b661c0> 
frame {{10, 10}, {851, 899}}
15/01/16 12:27:05,523 SOSmartBrowser[49595]: mapView <FBMapView: 0x81b661c0> 
bounds {{0, 0}, {851, 899}}

This can of course easily be fixed by doing

            [mapView setImageScaling:NSScaleProportionally]; // NSScaleNone is 
no good idea since the image might have Pixels=1702x1798 for Size={851, 899}

instead! :-) I understand the idea of NSBitmapImageRep generating the image 
with a higher resolution. This is actually pretty cool. 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?

Thanks a lot!!

Andreas








_______________________________________________

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