Fill Rect with Bitmap

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Fill Rect with Bitmap

Postby killa.fr0gg » Thu Apr 30, 2009 8:38 am

Hi all,

I'm trying to fill a Rect with a certain bitmap in my View's onDraw using the canvas.drawBitmap(), but I can't seem to make it move, it just gets cut off by my Rect.

the Rect sits at 0, 45, 300, 345, how do I fill it with my bitmap?

Thanks!
Last edited by killa.fr0gg on Thu Apr 30, 2009 11:04 am, edited 1 time in total.
killa.fr0gg
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Apr 21, 2009 9:35 am
Location: Los Angeles

Top

Postby padde » Thu Apr 30, 2009 10:01 am

Why dont you use the corresponding drawBitmap method?
http://developer.android.com/reference/android/graphics/Canvas.html

Look for "public void drawBitmap (Bitmap bitmap, Rect src, Rect dst, Paint paint)"


Greets
Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby killa.fr0gg » Thu Apr 30, 2009 11:02 am

Could you elaborate on this process please? I'm confused of the order of events for the entire process and it's not documented as far as I've found in any way that explains it fully.

Thank you.
killa.fr0gg
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Apr 21, 2009 9:35 am
Location: Los Angeles

Postby padde » Thu Apr 30, 2009 1:51 pm

Well.. you need 2 rects.. the first (src) defines which part of the bitmap you want to draw
and the second rect (dst) defines where to place and how to stretch/resize your bitmap.
If you want to draw the complete bitmap and not just a part try:

"drawBitmap(bitmap, null, new Rect(0, 45, 300, 345), new Paint());"

But that is all descripted on the site.. dont know what else to say.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby killa.fr0gg » Thu Apr 30, 2009 7:27 pm

Hi again,

Thanks again @padde, but again I was able to figure it out on my own in the wee hours of the morning (that seems to be the trick here...).

at any rate, a new problem has emerged: the ultimate goal is to be able to paint on the image with one's finger, and all of this works fine paintwise, but the coordinates are only accurate in the rect in the top-left corner, and get gradually less accurate as the drawpoints get further southwest. Is there some general quick-fix for this, or am I due for an entire rewriting of the painting methods?

Thanks much, all is very helpful.
killa.fr0gg
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Apr 21, 2009 9:35 am
Location: Los Angeles

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 19 guests