Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have this bitmap drawn on android canvas -

C#
protected void onDraw(Canvas canvas) {

            super.onDraw(canvas);

            Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic1);

            canvas.drawBitmap(myBitmap, 0, 0, null);

        }



How do I move the Bitmap to coordinates (100, 100) ?
Is there any way to do Translate Animation for Bitmap on android ?
Posted

1 solution

As in many other graphics rendering system, your code is the handler of some event invoked when the drawing is required. You hard-coded the bitmap coordinates, so what would you expect. You have to make these coordinate depending on some field(s) of declaring class, say, bitmapX, bitmapY. You modify the values of these fields and then redraw the view.

How? If I can assume that your code is declared in the class derived from the class SurfaceView, you can call one of the invalidate methods: http://developer.android.com/reference/android/view/SurfaceView.html[^].

It will eventually invoke the event (pun not intentional) cause re-rendering. Depending on invalidation method, it will redraw "dirty" area (rectangle, object, etc.). In your case, it should redraw at least the area calculated as the union of the "old" and "new" areas occupied by the bitmap.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900