• 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: Drawing an NSImage into a custom NSView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing an NSImage into a custom NSView


  • Subject: Re: Drawing an NSImage into a custom NSView
  • From: Marco Binder <email@hidden>
  • Date: Wed, 16 Oct 2002 10:45:15 +0200

I dont think that s a good idea. The image can be a different size than the view to draw in, so aRect will refer to different rect if not at 0,0 or at least, will not display the whole image, scaled to fit, as Marc probably wants. Thats why he really sould use compositeToRect (not compositeToPoint as previously suggested) and use two different rects (either, as he does, at a performance hit, the whole thing, or he has to convert the rects... a pain in the a**).

Second: when drawRect is called, the focus HAS BEEN locked already. At least, thats the way it should be. You never have to call lockFocus on yourself in a draw method, as far as I know.

NSCompositeCopy should work well.

On the other hand, I m clueless what might be going wrong, since it should work just the way Marc did it. That is, it workes for me.

Marc, maybe you should check again if your image is valid. It really should work the way you do it, if the image is correct. Why not put it in an NSImageView to check [imageView setImage:image];

Sorry I cant be of more help,

marco


Am Mittwoch, 16.10.02 um 09:37 Uhr schrieb Charles Srstka:

Actually, I'm about to slap myself in the face for not thinking of
this: there's an even easier, and better performance-wise solution than
using NSZeroRect. It is, simply:

- (void)drawRect:(NSRect)aRect {
[self lockFocus];
[image drawInRect:aRect
fromRect:aRect
operation:NSCompositeSourceOver // or whatever composite
operation you want
fraction:1.0];
[self unlockFocus];
}

This is the way I would do it. It beats both the imgSize, srcRect
method and NSZeroRect, because if some of the view is not visible, only
the visible part gets drawn. And it's very easy to type, and very
obvious, and I really should have thought of it when writing my first
reply. Oh well.

Charles

On Tuesday, October 15, 2002, at 10:09 PM, David Remahl wrote:

All I know is that it is a quick way to just draw the entire image,
and
that it works when I do it.

Ok. That is very interresting. I have always fonud the

NSSize imgSize = [img size];
NSRect srcRect = NSMakeRect( 0.0, 0.0, imgSize.width, imgSize.height );
[img drawImageFromRect:srcRect .....];

A real kludge. Using NSZeroRect would be nice both to performance
(although
not a lot) and to my typing fingers.

/ Rgds, David
_______________________________________________
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.
_______________________________________________
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.


--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
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.

References: 
 >Re: Drawing an NSImage into a custom NSView (From: Charles Srstka <email@hidden>)

  • Prev by Date: Re: Hardcopy Appkit Reference format?
  • Next by Date: Re: Hardcopy Appkit Reference format?
  • Previous by thread: Re: Drawing an NSImage into a custom NSView
  • Next by thread: Re: Drawing an NSImage into a custom NSView
  • Index(es):
    • Date
    • Thread