On Thu, Apr 22, 2010 at 1:08 AM, Indicator Veritatis <mej1...@yahoo.com> wrote:
> Are you calling the Drawable method setBounds()? Android Graphics will
> check to make sure the rendering is inside this rectangle before
> actually putting pixels on the screen.
>

It's a png I've loaded from drawable, I suppose setBounds() is called
when loading the image?

Dumbed down a bit am I doing (obj.myBitmap is a large bitmap
containing several images and I just want to show one, that's the
reason for haveing a source rect):
Rect vp = new Rect (100, 100, 400, 300);
public void draw (Canvas c)
{
   // normalize the position of the object
   Rect transformedPos = new Rect (obj.pos.left - vp.left, obj.pos.top
- vp.top, obj.pos.right - vp.left, obj.pos.top - vp.top);
   c.drawBitmap (obj.myBitmap, obj.imageMetricsRect, transformedPos, null);
}

This is called very frequently so I'd like to optimize it fairly well.
But at the same time if canvas does the same check would the trade off
of having the check all around to save a call doing the same thing not
be worth it. So to be precise this is what I would add:

Rect vp = new Rect (100, 100, 400, 300);
public void draw (Canvas c)
{
   // normalize the position of the object
   Rect tp = new Rect (obj.pos.left - vp.left, obj.pos.top - vp.top,
obj.pos.right - vp.left, obj.pos.top - vp.top);
   if (tp.left < vp.right && tp.right > vp.left && tp.top < vp.bottom
&& tp.bottom > vp.top)
       c.drawBitmap (obj.myBitmap, obj.imageMetricsRect, tp, null);
}

So I suppose my question is: Does Canvas just draw everythign being
thrown at it and then crops to the size of the screen or does it check
if there's a point drawing and then just draws the visible parts?

If it's option 1 I would assume that checking both if any portion of
the image is inside the screen and adjusting the src rect to be the
visible part would make sense?

> On Apr 21, 7:29 am, Jon mailinglists <jon.ml...@gmail.com> wrote:
>> Hi all,
>>
>> I just wonder if Canvas.draw... checks if I want to draw outside its
>> bounds and skips thoose parts or if I should do the math myself. The
>> case I'm having is that I have an update and the user has scrolled
>> away from that part of the screen. Should I bother adding an if
>> statement around the drawBitmap or is the only overhead that draw is
>> being called and just doesn't do anything?
>>
>> Thanks in advance
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Beginners" group.
>>
>> NEW! Try asking and tagging your question on Stack Overflow 
>> athttp://stackoverflow.com/questions/tagged/android
>>
>> To unsubscribe from this group, send email to
>> android-beginners+unsubscr...@googlegroups.com
>> For more options, visit this group 
>> athttp://groups.google.com/group/android-beginners?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Beginners" group.
>
> NEW! Try asking and tagging your question on Stack Overflow at
> http://stackoverflow.com/questions/tagged/android
>
> To unsubscribe from this group, send email to
> android-beginners+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-beginners?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to