Android and android Official Website

Source: Internet
Author: User

Android and android Official Website
Bitmap to Drawable

Bitmap bm=xxx; BitmapDrawable bd=new BitmapDrawable(bm);

Because BtimapDrawable is a subclass of Drawable, you can directly use the bd object.

Drawable to Bitmap
Drawable d=xxx; BitmapDrawable bd = (BitmapDrawable) d;Bitmap bm = bd.getBitmap();

Finally, bm is the Bitmap object we need.

Obtain Bitmap from resources
public static Bitmap getBitmapFromResources(Activity act, int resId) {    Resources res = act.getResources();    return BitmapFactory.decodeResource(res, resId);}
Byte [] → Bitmap
public static Bitmap convertBytes2Bimap(byte[] b) {    if (b.length == 0) {        return null;    }    return BitmapFactory.decodeByteArray(b, 0, b.length);}
Bitmap → byte []
public static byte[] convertBitmap2Bytes(Bitmap bm) {    ByteArrayOutputStream baos = new ByteArrayOutputStream();    bm.compress(Bitmap.CompressFormat.PNG, 100, baos);    return baos.toByteArray();}
Drawable → Bitmap
public static Bitmap convertDrawable2BitmapByCanvas(Drawable drawable) {    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight(),drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888: Bitmap.Config.RGB_565);    Canvas canvas = new Canvas(bitmap);    // canvas.setBitmap(bitmap);    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),    drawable.getIntrinsicHeight());    drawable.draw(canvas);    return bitmap;}
I am the dividing line of tiantiao
What language is used for Android software development?

What else does Javascript proficient android ahan.

What language is used for Android software development?

What else does Javascript proficient android ahan.

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.