Android--drawable && Bitmap

Source: Internet
Author: User

Bitmap Turn drawable
Bitmap bm=xxx; bitmapdrawable bd=new bitmapdrawable (BM);

Because Btimapdrawable is a subclass of drawable, it is finally possible to use the BD object directly.

drawable turn Bitmap
drawable d=== Bd.getbitmap ();

Finally, BM is the bitmap object we need.

get bitmap from your resources
 Public Static int resId) {    = 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  
bitmap→byte[]                                                                         
 public  static  byte  [] convertbitmap2bytes (Bitmap BM) {Bytearrayoutputstream BAOs  = Span style= "color: #0000ff;"    >new   Bytearrayoutputstream ();    Bm.compress (Bitmap.CompressFormat.PNG,  100 return   Baos.tobytearray ();}  
drawable→bitmap                                                                      
 public  static   Bitmap Convertdrawable2bitmapbycanvas (drawable drawable) {Bitmap Bitmap  = Bitmap.createbitmap (drawable.getin Trinsicwidth (), 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 return   bitmap;}  
I'm the dividing line of the king of the land Tiger.

Android--drawable && 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.