List of usage examples for android.graphics Bitmap recycle
public void recycle()
From source file:Main.java
public static byte[] toByteArray(final Bitmap bitmap) { final ByteArrayOutputStream output = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, output); bitmap.recycle(); return output.toByteArray(); }
From source file:Main.java
/** * @description get the scaled bitmap as request * * @param src/* w w w. ja v a2 s . c om*/ * @param dstWidth * @param dstHeight * @return */ private static Bitmap createScaleBitmap(Bitmap src, int dstWidth, int dstHeight, int inSampleSize) { Bitmap dst = Bitmap.createScaledBitmap(src, dstWidth, dstHeight, false); if (src != dst) { src.recycle(); } return dst; }
From source file:Main.java
public static Bitmap toAlpha(Bitmap src, Boolean recycle) { if (isEmptyBitmap(src)) return null; Bitmap ret = src.extractAlpha();/* w ww .j a va 2 s . co m*/ if (recycle && !src.isRecycled()) src.recycle(); return ret; }
From source file:Main.java
public static Bitmap cropBitmap(Bitmap source, int x, int y, int width, int height) { Bitmap bmp = Bitmap.createBitmap(source, x, y, width, height, null, false); if (source != null && bmp != source) { source.recycle(); }//from w w w . j a v a 2 s . c o m return bmp; }
From source file:Main.java
public static Point getImageDimension(Context context, int resource) { Bitmap bm = BitmapFactory.decodeResource(context.getResources(), resource); Point point = new Point(); point.x = bm.getWidth();/*www. ja va 2 s. c o m*/ point.y = bm.getHeight(); bm.recycle(); bm = null; return point; }
From source file:Main.java
/** * Bitmap -> byte/*from ww w . java 2s . co m*/ * * @param bitmap * @return */ public static byte[] bitmapToByte(Bitmap bitmap) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); bitmap.recycle(); bitmap = null; byte[] array = out.toByteArray(); return array; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Point getImageMaxDimension(Context context, int[] imgRes) { final Point point = new Point(); for (int i = 0, length = imgRes.length; i < length; i++) { Bitmap tmp = BitmapFactory.decodeResource(context.getResources(), imgRes[i]); int width = tmp.getWidth(); int height = tmp.getHeight(); tmp.recycle(); tmp = null;//from w ww . ja va2 s . c o m if (point.x < width) { point.x = width; } if (point.y < height) { point.y = height; } } return point; }
From source file:Main.java
public static Bitmap load_bitmap_from_uri_string(Context context, String uri, int sizeX, int sizeY) { Bitmap small_bitmap = null;/* w w w .j av a2 s . co m*/ Uri img_uri = Uri.parse(uri); if (uri != null) { try { InputStream inputStream = context.getContentResolver().openInputStream(img_uri); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); small_bitmap = Bitmap.createScaledBitmap(bitmap, sizeX, sizeY, false); bitmap.recycle(); } catch (FileNotFoundException e) { e.printStackTrace(); } } return small_bitmap; }
From source file:Main.java
/** * Returns a BitmapFactory.Options object containing the size of the image at the given URI, * without actually loading the image.//from www .j av a2 s . c o m */ public static BitmapFactory.Options computeBitmapSizeFromURI(Context context, Uri imageURI) throws FileNotFoundException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(imageURI), null, options); if (bitmap != null) { bitmap.recycle(); } return options; }
From source file:Main.java
public static void recycleImageView(View view) { if (view == null) return;//from www.j a v a 2 s. c o m if (view instanceof ImageView) { Drawable drawable = ((ImageView) view).getDrawable(); if (drawable instanceof BitmapDrawable) { Bitmap bmp = ((BitmapDrawable) drawable).getBitmap(); if (bmp != null && !bmp.isRecycled()) { ((ImageView) view).setImageBitmap(null); bmp.recycle(); bmp = null; } } } }