• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to draw whole NSImage inside custom rect in NSView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to draw whole NSImage inside custom rect in NSView


  • Subject: Re: How to draw whole NSImage inside custom rect in NSView
  • From: Alexander Shmelev <email@hidden>
  • Date: Wed, 12 Nov 2008 01:40:51 +0300

Hi, Ken

Thank you for answer.
But simple color filling was first what I have tried.
When I add following code inside -(void)drawRect method, it fills exactly maxScanArea:
[[NSColor whiteColor] set];
[NSBezierPath fillRect:maxScanArea];
But -(void)drawInRect:maxScanArea places picture outside maxScanArea.



My target is to implement NSImage preview window with drag-n-drop selection frame, like Select Tool in Preview.app. May be such custom control exists and I simply do not know about it. But until I find something suitable I have to deal with drawInRect:... issue.



On 12.11.2008, at 1:28, Ken Ferry wrote:

Hi Alexander,

Your code will draw the image in maxScanArea.  You should probably
look for a bug elsewhere.

I like to replace complex drawing with simple color fills when
debugging drawing location issues.  At least it limits what could go
wrong.

-Ken

On Tue, Nov 11, 2008 at 2:17 PM, Alexander Shmelev <email@hidden> wrote:
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


_______________________________________________

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


References: 
 >How to draw whole NSImage inside custom rect in NSView (From: Alexander Shmelev <email@hidden>)
 >Re: How to draw whole NSImage inside custom rect in NSView (From: "Ken Ferry" <email@hidden>)

  • Prev by Date: Re: A bit of a dumb question, but I need to know...
  • Next by Date: Re: A bit of a dumb question, but I need to know...
  • Previous by thread: Re: How to draw whole NSImage inside custom rect in NSView
  • Next by thread: Re: How to draw whole NSImage inside custom rect in NSView
  • Index(es):
    • Date
    • Thread