Android: Canvas Draw, Rotate, Move and Resize Component

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

Android: Canvas Draw, Rotate, Move and Resize Component

Postby nisha.113a5 » Sat Jan 21, 2012 7:35 am

hi everybody,

I wanted to draw components on canvas. Drawing colorful text on is completely done with layouts of android. In below picture, i have put some colorful text on bitmap through layout. But need to implement same on canvas. How to do this with canvas?

Thanks a lot of
Attachments
Untitled.png
Untitled.png (223.44 KiB) Viewed 556 times
Nisha
nisha.113a5
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sat Sep 19, 2009 12:35 pm

Top

Re: Android: Canvas Draw, Rotate, Move and Resize Component

Postby Phyll » Sat Jan 21, 2012 1:49 pm

Hi nisha,

Here's an example of drawing on the canvas of a bitmap. Once you have a bitmap, you can place it on the screen just like any other image, or send it or whatever. You can also use this same technique to draw in the ondraw method of a view.

Code: Select all
          public Bitmap buildUpdateTime(String time) { Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444);;
              Canvas myCanvas = new Canvas(myBitmap);
              Paint paint = new Paint();
                                        //To use own font
              //Typeface clock = Typeface.createFromAsset(this.getAssets(),"Carre.ttf");
              paint.setAntiAlias(true);
              paint.setSubpixelText(true);
              paint.setTypeface(clock);
              paint.setStyle(Paint.Style.FILL);
              paint.setColor(Color.RED);
              paint.setTextSize(65);
              paint.setTextAlign(Align.CENTER);
              myCanvas.drawText(time, 80, 60, paint);
              return myBitmap;             
          }


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: MSNbot Media and 9 guests