List of utility methods to do Bitmap Compress
void | bitmap2File(Bitmap bitmap, File file, CompressFormat format, int quality) bitmap File if (bitmap == null) { throw new NullPointerException("source bitmap is null..."); if (file == null) { throw new NullPointerException("targe file is null..."); if (file.exists()) { file.delete(); ... |
InputStream | bitmap2Stream(Bitmap bitmap, CompressFormat format, int quality) bitmap Stream ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(format, quality, baos); InputStream stream = new ByteArrayInputStream(baos.toByteArray()); return stream; |
File | compressBitmapToFile(Bitmap originalBitmap, String path, int quality) compress Bitmap To File File file = new File(path); File filePath = file.getParentFile(); if (!filePath.exists()) { filePath.mkdirs(); if (!file.exists()) { try { file.createNewFile(); ... |
byte[] | compressToBytes(Bitmap bitmap) compress To Bytes return compressToBytes(bitmap, DEFAULT_JPEG_QUALITY);
|
byte[] | compressToBytes(Bitmap bitmap, int quality) compress To Bytes ByteArrayOutputStream baos = new ByteArrayOutputStream(65536); bitmap.compress(CompressFormat.JPEG, quality, baos); return baos.toByteArray(); |
byte[] | flattenBitmap(Bitmap bitmap) flatten Bitmap int size = bitmap.getWidth() * bitmap.getHeight() * 4; ByteArrayOutputStream out = new ByteArrayOutputStream(size); try { bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); out.flush(); out.close(); return out.toByteArray(); } catch (IOException e) { ... |
File | smallPic(String oldPath, String newPath, int size) small Pic BitmapFactory.Options opts = new BitmapFactory.Options(); Bitmap resizeBmp; opts.inSampleSize = size; opts.inJustDecodeBounds = false; resizeBmp = BitmapFactory.decodeFile(oldPath, opts); File pictureFile = new File(newPath); try { if (pictureFile.exists()) { ... |
Bitmap | compressWithWidth(Bitmap bitmap, int width) compress With Width BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; int bmpWidth = options.outWidth; int bmpHeight = options.outHeight; options.inJustDecodeBounds = false; float scaleWidth = bmpWidth; float scaleHeight = bmpHeight; if (bmpWidth > width) { ... |
Bitmap | compressWithWidth(String filePath, int width) compress With Width BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeFile(filePath, options); int bmpWidth = options.outWidth; int bmpHeight = options.outHeight; options.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeFile(filePath, options); float scaleWidth = bmpWidth; ... |
byte[] | compressBitmap(Bitmap bitmap) compress Bitmap ByteArrayOutputStream os = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, COMPRESS_JPEG_QUALITY, os); return os.toByteArray(); |