当前位置: 代码迷 >> Android >> Android Drawable变换为Bitmap
  详细解决方案

Android Drawable变换为Bitmap

热度:10   发布时间:2016-05-01 18:48:32.0
Android Drawable转换为Bitmap
public static Bitmap drawableToBitmap(Drawable drawable) {	try {		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;	} catch (OutOfMemoryError e) {		e.printStackTrace();		return null;	}}
  相关解决方案