List of usage examples for android.graphics Bitmap recycle
public void recycle()
From source file:Main.java
/** * // w w w . ja va 2 s. co m * @return Bitmap's RGBA byte array */ public static byte[] getImageRGBA(Bitmap inputBitmap) { Config config = inputBitmap.getConfig(); ByteBuffer buffer; Bitmap bitmap; /** * if bitmap size is not 32*32 create scaled bitmap */ if (inputBitmap.getWidth() != 32 || inputBitmap.getHeight() != 32) { Log.d(TAG, "bitmap resized to 32x32"); bitmap = Bitmap.createScaledBitmap(inputBitmap, 32, 32, false); } else { bitmap = inputBitmap; } /** * if bitmap is not ARGB_8888 format, copy bitmap with ARGB_8888 format */ if (!config.equals(Bitmap.Config.ARGB_8888)) { Bitmap bitmapARBG = bitmap.copy(Bitmap.Config.ARGB_8888, false); buffer = ByteBuffer.allocate(bitmapARBG.getByteCount()); bitmapARBG.copyPixelsToBuffer(buffer); bitmapARBG.recycle(); } else { buffer = ByteBuffer.allocate(bitmap.getByteCount()); bitmap.copyPixelsToBuffer(buffer); } return buffer.array(); }
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap bitmap, int degress, boolean needRecycle) { Matrix m = new Matrix(); m.postRotate(degress);/* www. jav a 2 s .co m*/ Bitmap bm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); if (needRecycle) { bitmap.recycle(); } return bm; }
From source file:Main.java
public static byte[] bitmap2Bytes(Bitmap bm, Bitmap.CompressFormat format, int quality) { try {//from w ww . ja v a2s . co m ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(format, quality, baos); return baos.toByteArray(); } finally { bm.recycle(); } }
From source file:Main.java
public static Bitmap scale(Bitmap bitmap, float scale) { Matrix matrix = new Matrix(); matrix.postScale(scale, scale);/*from ww w . j a v a 2s .c o m*/ Bitmap outBitmap = Bitmap.createBitmap(bitmap, 0, 0, (int) (bitmap.getWidth()), (int) (bitmap.getHeight()), matrix, true); bitmap.recycle(); return outBitmap; }
From source file:Main.java
public static byte[] bitmapToNV21(int inputWidth, int inputHeight, Bitmap bitmap) { int[] argb = new int[inputWidth * inputHeight]; bitmap.getPixels(argb, 0, inputWidth, 0, 0, inputWidth, inputHeight); byte[] yuv = ARGBtoYUV420SemiPlanar(argb, inputWidth, inputHeight); bitmap.recycle(); return yuv;//from ww w .j a v a 2 s . c o m }
From source file:Main.java
public static void saveRgb2Bitmap(IntBuffer buf, String filePath, int width, int height) { final int[] pixelMirroredArray = new int[width * height]; Log.d("TryOpenGL", "Creating " + filePath); BufferedOutputStream bos = null; try {/*from w ww. ja v a 2s . c om*/ int[] pixelArray = buf.array(); // rotate 180 deg with x axis because y is reversed for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { pixelMirroredArray[(height - i - 1) * width + j] = pixelArray[i * width + j]; } } bos = new BufferedOutputStream(new FileOutputStream(filePath)); Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bmp.copyPixelsFromBuffer(IntBuffer.wrap(pixelMirroredArray)); bmp.compress(Bitmap.CompressFormat.JPEG, 90, bos); bmp.recycle(); } catch (IOException e) { e.printStackTrace(); } finally { if (bos != null) { try { bos.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.carlrice.reader.utils.UiUtils.java
static public Bitmap getScaledBitmap(byte[] iconBytes, int sizeInDp) { if (iconBytes != null && iconBytes.length > 0) { Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length); if (bitmap != null && bitmap.getWidth() != 0 && bitmap.getHeight() != 0) { int bitmapSizeInDip = UiUtils.dpToPixel(sizeInDp); if (bitmap.getHeight() != bitmapSizeInDip) { Bitmap tmp = bitmap; bitmap = Bitmap.createScaledBitmap(tmp, bitmapSizeInDip, bitmapSizeInDip, false); tmp.recycle(); }//ww w . ja va2 s .c om return bitmap; } } return null; }
From source file:Main.java
public static String getImageAsString(Bitmap bmp) { ByteArrayOutputStream bYtE = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, bYtE); byte[] byteArray = bYtE.toByteArray(); String image = Base64.encodeToString(byteArray, Base64.DEFAULT); bmp.recycle(); Log.d("Converted TO : ", image); return image; }
From source file:Main.java
public static Bitmap mirrorImage(@NonNull Bitmap resultBitmap) { Matrix matrix = new Matrix(); matrix.preScale(-1.0f, 1.0f);//ww w.j a v a 2 s. c om Bitmap returnBitmap = Bitmap.createBitmap(resultBitmap, 0, 0, resultBitmap.getWidth(), resultBitmap.getHeight(), matrix, false); resultBitmap.recycle(); return returnBitmap; }
From source file:Main.java
private static Bitmap createScaledBitMap(Bitmap src, int destWidth, int destHeight) { // TODO Auto-generated method stub if (src == null) { return null; }//from w ww . j a v a 2 s . c o m Bitmap dest = Bitmap.createScaledBitmap(src, destWidth, destHeight, false); if (dest != src) { src.recycle(); } return dest; }