Conversion of bitmap and drawable to each other

Source: Internet
Author: User

Just before the project is useful, afraid of forgetting, it is first recorded, and then will use the time directly to copy the use of the good.

1.Bitmap---->drawable:

   public static drawable bitmaptodrawable (Bitmap Bitmap) {        bitmapdrawable bd = new bitmapdrawable (Bitmap);        return BD;    }

2.Drawable---->bitmap:

    public static Bitmap Drawabletobitmap (drawable drawable) {        //Take Drawable's long width        int w = drawable.getintrinsicwidth () ;        int h = drawable.getintrinsicheight ();        Take drawable color format        bitmap.config Config = drawable.getopacity ()! = Pixelformat.opaque? Bitmap.Config.ARGB_8888                : Bitmap.Config.RGB_565;        Bitmap Bitmap = Bitmap.createbitmap (w, H, config);        Canvas canvas = new canvas (bitmap);        Drawable.setbounds (0, 0, W, h);        Drawable.draw (canvas);        return bitmap;    }

That is over!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Conversion of bitmap and drawable to each other

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.