How to draw whole NSImage inside custom rect in NSView
How to draw whole NSImage inside custom rect in NSView
- Subject: How to draw whole NSImage inside custom rect in NSView
- From: Alexander Shmelev <email@hidden>
- Date: Wed, 12 Nov 2008 01:17:33 +0300
Hello
I have custom NSView, and want to draw whole NSImage inside some
custom rectangular area of NSView.
I tried to use [NSImage drawInRect:...] but result does not fit
desired rectangular area of NSView.
My code:
- (void) setPreviewWidth:(float)width height:(float)height
{
margin = width / 25;
maxScanArea = NSMakeRect(margin, margin, width, height);
canvasArea = NSMakeRect(0, 0, width + 2.0 * margin, height + 2.0 *
margin);
[self setBounds:canvasArea];
}
- (void) drawRect:(NSRect)rect
{
// Drawing image in preview
if (image) {
NSRect imageRect;
imageRect.origin = NSZeroPoint;
imageRect.size = [image size];
[image drawInRect:maxScanArea
fromRect:imageRect
operation:NSCompositeSourceOver
fraction:1];
// I want image to be drawn in maxScanArea rect, but it is drawn in
[self bounds] rect.
}
}
Could you advise how can I draw exactly inside maxScanArea NSRect in
NSView?
BR, Alexander.
_______________________________________________
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