List of usage examples for android.graphics.drawable BitmapDrawable getBitmap
public final Bitmap getBitmap()
From source file:Main.java
public static Bitmap toBitmap(Drawable drawable) { BitmapDrawable bd = (BitmapDrawable) drawable; Bitmap bm = bd.getBitmap(); return bm; }
From source file:Main.java
public static void cleanImageView(ImageView imageView) { if (!(imageView.getDrawable() instanceof BitmapDrawable)) return;//w w w .ja va2 s . co m //Clean up the view's image for the sake of memory BitmapDrawable b = (BitmapDrawable) imageView.getDrawable(); b.getBitmap().recycle(); imageView.setImageDrawable(null); }
From source file:Main.java
public static void cleanImageView(ImageView imageView) { if (!(imageView.getDrawable() instanceof BitmapDrawable)) return;//from www .ja va2 s . c om // clean up the view's image for the sake of memory BitmapDrawable b = (BitmapDrawable) imageView.getDrawable(); b.getBitmap().recycle(); imageView.setImageDrawable(null); }
From source file:Main.java
/** * Rotate the image.// w w w . j a va 2s . c o m * * @param drawable */ public static BitmapDrawable rotateImage(BitmapDrawable drawable, int degree) { Bitmap bitmap = drawable.getBitmap(); Matrix matrix = new Matrix(); matrix.postRotate(degree); Bitmap rotatedBMP = Bitmap.createBitmap(drawable.getBitmap(), 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); return new BitmapDrawable(rotatedBMP); }
From source file:Main.java
/** * Cleans up view's image to reduce memory cost to device * @param imageView/* w w w . ja v a 2 s.c o m*/ */ static void cleanImageView(ImageView imageView) { if (!(imageView.getDrawable() instanceof BitmapDrawable)) return; // clean up the view's image for the sake of memory BitmapDrawable b = (BitmapDrawable) imageView.getDrawable(); b.getBitmap().recycle(); imageView.setImageDrawable(null); }
From source file:Main.java
public static Bitmap DrawableToBitmap(Drawable drawable) { // Bitmap bitmap = Bitmap.createBitmap( ///* w w w .j a v a2s .c o m*/ // drawable.getIntrinsicWidth(), // // drawable.getIntrinsicHeight(), // // drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 // : Bitmap.Config.RGB_565); // Canvas canvas = new Canvas(bitmap); // drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); // drawable.draw(canvas); BitmapDrawable bd = (BitmapDrawable) drawable; return bd.getBitmap(); }
From source file:Main.java
private static Bitmap getBitmapFromResourceId(Context context, int id, int density) { Drawable drawable = null;/*from w w w .ja va 2 s.c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { drawable = context.getResources().getDrawableForDensity(id, density); } else { drawable = context.getResources().getDrawable(id); } if (drawable instanceof BitmapDrawable) { BitmapDrawable bd = (BitmapDrawable) drawable; return bd.getBitmap(); } assert false : "The drawable was not a bitmap drawable as expected"; return null; }
From source file:Main.java
public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable); return bitmapDrawable.getBitmap(); } else {/*from www.j av a 2 s. c om*/ 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); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap; } }
From source file:Main.java
public static byte[] drawableToBytes(Drawable drawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; Bitmap bitmap = bitmapDrawable.getBitmap(); byte[] bytes = bitmapToBytes(bitmap); ;// w ww. j av a 2 s .c o m return bytes; }
From source file:Main.java
public static void recycleImageViewBitmap(ImageView imageView) { if (imageView == null) return;// w w w . j a v a 2 s . c o m Drawable drawable = imageView.getDrawable(); if (drawable != null && drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; Bitmap bitmap = bitmapDrawable.getBitmap(); if (bitmap != null && !bitmap.isRecycled()) { bitmap.recycle(); } } }