List of usage examples for android.graphics Bitmap compress
@WorkerThread public boolean compress(CompressFormat format, int quality, OutputStream stream)
From source file:Main.java
public static byte[] bitmap2Byte(Bitmap bitmap) { if (bitmap == null) { return null; }//from www . j a v a 2 s . com int size = bitmap.getWidth() * bitmap.getHeight(); ByteArrayOutputStream baos = new ByteArrayOutputStream(size); bitmap.compress(CompressFormat.JPEG, 100, baos); return baos.toByteArray(); }
From source file:Main.java
public static void writeTofiles(Context context, Bitmap bitmap, String filename) { BufferedOutputStream outputStream = null; try {/*w ww . j a v a 2s . c o m*/ outputStream = new BufferedOutputStream(context.openFileOutput(filename, Context.MODE_PRIVATE)); bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean saveBitmap(Bitmap bitmap, File file) { if (bitmap == null) return false; FileOutputStream fos = null;/*from w w w . j av a2 s .c o m*/ try { fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); return true; } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } return false; }
From source file:com.example.sergey.currentweather.app.JSONWeatherParser.java
private static Weather convertBitmapIntoByteArray(Weather result, Bitmap image) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); result.setIconArray(byteArray);/* w ww . j a v a 2 s .c o m*/ return result; }
From source file:Main.java
public static boolean saveBitmap(Bitmap bitmap, File file) { if (bitmap == null) return false; FileOutputStream fos = null;// ww w. j ava 2s . co m try { fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos); fos.flush(); return true; } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } return false; }
From source file:Main.java
public static boolean saveBitmap(Bitmap bitmap, File file) { if (bitmap == null) return false; FileOutputStream fos = null;/*from w w w.j a va2s. c o m*/ try { fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); return true; } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } return false; }
From source file:com.appnexus.opensdk.PBImplementation.java
private static byte[] BitmapToByte(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream)) { return stream.toByteArray(); }/*from w ww. jav a 2 s . c o m*/ return null; }
From source file:Main.java
public static void saveBitmap(Bitmap bitmap, File bitmapFile) { try {/* w w w .ja v a 2s.co m*/ if (bitmap != null && bitmap.getWidth() > 0 && bitmap.getHeight() > 0) { FileOutputStream out = new FileOutputStream(bitmapFile); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void saveBitmap(Bitmap bitmap, String filePath) { File f = new File(filePath); if (f.exists()) { return;//from www . j a va 2 s . co m } try { FileOutputStream out = new FileOutputStream(f); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean saveBitmap(Bitmap bitmap, File file) { if (bitmap == null) return false; FileOutputStream fos = null;/*from www. j ava 2s. c o m*/ try { fos = new FileOutputStream(file, false); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); return true; } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } return false; }