Android in the design interface Drawable,canvas, and bitmap

Source: Internet
Author: User

Drawable graphical objects, you can reprint images in a common format, which may be (bitmaps) bitmapdrawable, or shapedrawable (graphics), or many other picture formats GIF,PNG,JEPG

Two. Bitmap is a bitmap for image processing

Three. Canvas, which is the target area for painting, is used to manage bitmp or path paths

Here's how to convert drawable into bitmap.

I know there are two methods (two methods who are good and who are bad, depends on the situation)

(1) A common way is to create a bitmap, and then use the canvas to bind the bitmap, drawable to bitmap (this method for the Drawable object at this time is not bitmap image)

Bitmap bitmap=bitmap.createbitmap (size, size, Bitmap.Config.ARGB_8888);//Create a bitmap with a size wide size height canvas canvas=new Canvas (bitmap);//Bind the canvas to the bitmap and prepare for the next drawable painting Drawable.setbounds (0,0,size,size);// Drawable set the same size as the bitmap drawable.draw (canvas);//Will drawable through the canvas to bitmap up

(2) Another way is to get bitmap directly (bitmapdrawable)

Bitmap Icon=bitmapfactory.decoderesource (Context.getresources (), R.drawable.icon_resource)//drawable in Icon_ object Resource image conversion to bitmap file icon

Or

bitmapdrawable BD = (bitmapdrawable) drawable;//first converted to bitdrawable         bitmap = Bd.getbitmap ();//again via Getbitmap () Get to Bitmap

The first to get here, in the future continue to add after depth!

Android in the design interface Drawable,canvas, and bitmap

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.