Android Drawable 转化成 Bitmap

/*Java代码  将Drawable转化为Bitmap */
  Bitmap drawableToBitmap(Drawable drawable)
  {
   int width = drawable.getIntrinsicWidth();
   int height = drawable.getIntrinsicHeight();
          
   Bitmap bitmap = Bitmap.createBitmap(width, height,drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888: Bitmap.Config.RGB_565);
   Canvas canvas = new Canvas(bitmap);
   //canvas.drawColor(0xff33B5E5);       
   drawable.setBounds(0,0,width,height);
   drawable.draw(canvas);
           
   return bitmap;      
  }

上一篇:前端 跨域


下一篇:HorizontalScrollView不显示滚动条,布局完全填充的方法