Android编程之图片相关代码集锦

2019-12-10 19:53:55王振洲
  • */  public static Drawable resourceToDrawable(Context context,int id) {  
  • return null == context ? null : bitmapToDrawable(BitmapFactory.decodeResource(context.getResources(), id));   }  

    byte数组转换Drawble对象:

     

     
    1. /**   * @param bytes byte数组  
    2. * @return drawble对象   */ 
    3. public static Drawable byteArrayToDrawable(byte[] bytes) {   return null == bytes ? null : bitmapToDrawable(BitmapFactory.decodeByteArray(bytes, 0, bytes.length));  
    4. }  

    4.Drawable转化为bitmap:

     

     
    1. /**   * Drawble对象转Bitmap对象  
    2. * @param drawable drawble对象   * @return bitmap对象