Scaling an NSImage makes the edges disappear.
Scaling an NSImage makes the edges disappear.
- Subject: Scaling an NSImage makes the edges disappear.
- From: "David Springer" <email@hidden>
- Date: Thu, 21 Aug 2008 13:47:09 -0600
Folks,
For some reason, I am not able to figure this out. I want to draw a
scaled NSImage, but the edges of the image are not drawn, it seems
like the resizing actually clips the image.
I have an NSBitmapImageRep created from some data. I then create the
NSImage like this:
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize([myBitmap
pixelsWide], [myBitmap pixelsHigh]);
[image addRepresentation:myBitmap];
[image setScalesWhenResized:YES];
// Figure out the new image size so that it is proportionally scaled
by |scaleFactor|.
NSSize scaledSize = ProportionallyScale([image size], scaleFactor);
[image drawInRect:NSMakeRect((kTileImageSize - scaledSize.width) * 0.5,
(kTileImageSize - scaledSize.height) * 0.5,
scaledSize.width,
scaledSize.height)
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0];
This sometimes works (that is, the entire original image is visible).
But more often than not, the edges of the original image are not
drawn. See the screen shots for a picture of what I get.
What am I doing wrong here? I have scoured the archives, I have tried
things like making sure scaledSize has integer values, I have even
done crazy things like add one to the height just to see what would
happen. Note that if I write out the TIFFRepresentation of |image|
(both before and after) the entire image gets into the file (that is,
the edges are not clipped).
In the attached picture, the top tile is correct (you see all the
black edges), the bottom two tiles are incorrect (not all the black
edges are visible).
Help?
Thanks!
- Dave.S
Attachment:
badthumbs.tiff
Description: TIFF image
_______________________________________________
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