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

2019-12-10 19:53:55王振洲
  • */  public static Bitmap drawableToBitmap(Drawable drawable) {  
  • return null == drawable ? null : ((BitmapDrawable) drawable).getBitmap();   }  

    5.byte数组转换Bitmap对象:

     

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

    6.图片去色,返回灰度图片(老式图片):

     

     
    1. /**   * @param bitmap 传入的bitmap  
    2. * @return 去色后的图片Bitmap对象   */ 
    3. public static Bitmap toGrayscale(Bitmap bitmap) {   int width,height;