Re: Getting actual size of NSImage in NSImageView?
Re: Getting actual size of NSImage in NSImageView?
- Subject: Re: Getting actual size of NSImage in NSImageView?
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 29 Apr 2003 16:07:09 -0700
On Tuesday, April 29, 2003, at 03:23 PM, email@hidden wrote:
I'm doing some dragging out of an NSImageView subclass, and I want the
"dragImage" to be not the original image that is scaled down to fit
inside the NSImageView, but a copy of the image that it the same size
as what's displayed. (Otherwise, the original image, which is much
bigger, pops up out of seemingly nowhere!)
I can ask the NSImageView for its size, and size the image to be that
-- but that doesn't handle the proportions correctly, so the image is
still not right.
Any suggestions for asking the NSImageView, or its NSImage, what size
it is *currently* displaying at?
// CODE SNIPPET -- CLOSE, BUT NOT QUITE.
- dragImage
{
#warning -- not quite right.
NSSize viewSize = [self bounds].size;
NSImage *newImage = [[[self image] copy] autorelease];
[newImage setScalesWhenResized:YES];
[newImage setSize:viewSize];
return newImage;
}
In the "Cropped Image" sample, I worked around it like so:
@implementation NSImageCell (CroppingImageView)
- (NSRect) rectCoveredByImageInBounds:(NSRect) bounds
// This is a work-around to deal with the fact that NSImageCell won't
tell me the rectangle *actually* covered by its image, but NSCell will.
{
return [super imageRectForBounds:bounds];
}
@end
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.