Replacing drawed pictures in canvas

Put your problem here if it does not fit any of the other categories.

Replacing drawed pictures in canvas

Postby BossOss » Wed Feb 29, 2012 9:56 am

Hi guys,
I'm writing here now because the other sub forums seem to be flooded ....
i have a project where i have to place ressources (.png files) on a view. These ressources shall replace the self-drawed android.graphics.Picture objects on the view. The pictures are built up and passed on the following way:

Code: Select all
picture = new Picture();
canvas = picture.beginRecording(0, 0);
Reference.paint.setColor(getResources().getColor(R.drawable.col_listener));
Reference.paint.setStrokeWidth(3.0f);
canvas.drawLine(-12.0f, 0.0f, 13.0f,  0.0f, Reference.paint);
Reference.paint.setStrokeWidth(2.0f);
canvas.drawLine( 15.0f, 0.0f, -1.0f, -10.0f, Reference.paint);
canvas.drawLine( 15.0f, 0.0f, -1.0f,  10.0f, Reference.paint);
picture.endRecording();
Reference.arrowPicture = picture;


at the Reference class its processed like this:

Code: Select all
@Override
   public void draw(Canvas canvas, float inverseScaling, float counterRotation) {
      canvas.save();
      canvas.scale(inverseScaling, -inverseScaling);
      arrowPicture.draw(canvas);
      canvas.restore();
   }


Instead of the drawn picture i want a given ressource file to be processed instead and to be drawn on the canvas.
Does anyone have an smart solution for that?

Greetz
BossOss
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Jan 09, 2012 2:54 pm

Top

Re: Replacing drawed pictures in canvas

Postby Phyll » Wed Feb 29, 2012 12:49 pm

Hi BossOss,

Flooded? You mean the spam we just got hit with here? Nobody does anything about it.

Here's some code to get a bitmap from resources then draw it:

Code: Select all
//gloabal bitmap if it needs to be done a lot
public Bitmap head = Bitmap.createBitmap(251,283, Bitmap.Config.ARGB_8888);

//load it from resources
head = BitmapFactory.decodeResource(getResources(),R.drawable.small_head);

//put it on the canvas
canvas.drawBitmap(head, left, top, paint);


There are lots of drawBitmap()s that might work. This one may not be the best.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 17 guests