Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing into a HIImageView



On 02.08.2007, at 14:48, Peter Ueli wrote:
I thought that I can use a hiImageView and draw with Quarz into it. Unfortunately I have some trouble in implementing it. For Quarz drawings, I need a Context. right? In the Quarz2d guide I read that I need a keventcontolDraw Event to get the context.

Either/Or, not both. Either you draw into a CGImage and display that in an HIImageView, or you create a custom view and override kEventControlDraw. If you do both, your CGImage will never be drawn, because you're doing your own drawing and not letting the HIImageView's built-in kEventControlDraw draw the image.


The problem is the following: If I want to draw a square into the imageview, I store the coordinates into a global variable and call hiviewsetneedsdisplay to get the controlDraw event. Then in the event handler I get the context with getEventParameters.
This works fine. But if I want to draw a second square, over the first one. The first one gets lost (because of the redraw of the hiimageview). How can I draw something new into the imageview without losing the old content?

That's how kEventControlDraw is supposed to work. It redraws the view whenever it needs redrawing. What you really want to do is create a CGBitmapContext, draw into that, and then create a CGImageRef from that which the HIImageView will draw. Or just do your *complete* drawing in a custom view's kEventControlDraw.


I tried also to store the context reference globaly an then draw to it whenever I wan't to draw to it. But then the drawings are not drawn into the imageview but somwehere else in the window.

No, you don't need to do that. The context ref isn't even guaranteed to stay the same (or valid, for that matter) after your kEventControlDraw returns. Create your own bitmap context and draw into that, then do a setNeedsDisplay to actually cause the redraw. You might even be able to directly draw the bitmap context's contents from a custom view, without going through a CGImage, I can't remember right now.


Cheers,
-- M. Uli Kusterer
"The Witnesses of TeachText are everywhere..."


_______________________________________________ Do not post admin requests to the list. They will be ignored. Carbon-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Drawing into a HIImageView (From: "Peter Ueli" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.