Re: NSImage size
Re: NSImage size
- Subject: Re: NSImage size
- From: Tom Waters <email@hidden>
- Date: Mon, 26 Nov 2001 15:50:51 -0800
you are asking for the image to be scaled FROM (see fromRect: parameter)
an arbitrary rectangle that was most recently damaged on the screen...
e.g. the rect passed into drawRect.
that rectangle has no bearing on the size of your image, nor the bounds
of your view. you should only use it for performance optimization.
the right code for a replacement for NSImageView (in stretch mode) is:
(note, i threw the image in the bundle and used imageNamed:)
#import <Cocoa/Cocoa.h>
@interface ImageView : NSView
{
NSImage *image;
}
@end
@implementation ImageView
- (id)initWithFrame:(NSRect)rect
{
if (self = [super initWithFrame:rect]) {
image = [NSImage imageNamed: @"aTiffImage.tiff"];
}
return self;
}
- (void)drawRect:(NSRect)rect
{
[image drawInRect:[self bounds]
fromRect:NSZeroRect // this is a shorthand for "the whole image"
operation:NSCompositeCopy fraction:1.0];
}
@end
On Sunday, November 25, 2001, at 01:08 AM, Dan Huntsinger wrote:
Hi everybody,
Another quick question:
I am trying to display an image in my NSView sublcass, and here's the
code I
have for the drawRect method so far:
- (void)drawRect:(NSRect)rect
{
NSString *title;
NSImage *image;
title = [[NSBundle mainBundle] pathForImageResource:@"aTiffImage"];
image = [[NSImage alloc] initWithContentsOfFile:title];
[image setSize:NSMakeSize(100,150)];
[image compositeToPoint:NSMakePoint(0,0) fromRect:rect
operation:NSCompositeCopy fraction:1.0];
}
No matter what I do, I keep getting a "little" image displayed, instead
of
the actual bigger size of the image, or the image size I set. Why
doesn't
the setSize: method work in the above code?
Thanks,
Dan
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
References: | |
| >NSImage size (From: Dan Huntsinger <email@hidden>) |