List of usage examples for java.io ByteArrayOutputStream toByteArray
public synchronized byte[] toByteArray()
From source file:Main.java
private static byte[] bitmap2Bytes(final Bitmap bitmap) { if (bitmap == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); }
From source file:MainClass.java
private static byte[] passwordEncrypt(char[] password, byte[] plaintext) throws Exception { int MD5_ITERATIONS = 1000; byte[] salt = new byte[8]; SecureRandom random = new SecureRandom(); random.nextBytes(salt);// w w w . j av a 2 s. co m PBEKeySpec keySpec = new PBEKeySpec(password); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithSHAAndTwofish-CBC"); SecretKey key = keyFactory.generateSecret(keySpec); PBEParameterSpec paramSpec = new PBEParameterSpec(salt, MD5_ITERATIONS); Cipher cipher = Cipher.getInstance("PBEWithSHAAndTwofish-CBC"); cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec); byte[] ciphertext = cipher.doFinal(plaintext); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(salt); baos.write(ciphertext); return baos.toByteArray(); }
From source file:Main.java
public static byte[] formatByteArray(Bitmap bitmap) { byte[] data;//from ww w. jav a 2s. c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); data = baos.toByteArray(); return data; }
From source file:Main.java
public static byte[] bitmap2Bytes(Bitmap bitmap) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); }
From source file:Main.java
/** * This method converts a bitmap image to a byte array. * * @param bm/*www . ja v a 2 s . com*/ * @return */ public static byte[] getBytesFromBitmap(Bitmap bm) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, stream); return stream.toByteArray(); }
From source file:Main.java
public static int getBmpSize(Bitmap bmp) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] b = baos.toByteArray(); return b.length; }
From source file:Main.java
public static byte[] Bitmap2Jpeg(Bitmap src) { ByteArrayOutputStream os = new ByteArrayOutputStream(); src.compress(Bitmap.CompressFormat.JPEG, 50, os); byte[] array = os.toByteArray(); return array; }
From source file:Main.java
public static byte[] getBytes(Bitmap bitmap) { if (bitmap == null) return null; ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream); return stream.toByteArray(); }
From source file:Main.java
public static byte[] getBitmapAsByteArray(Bitmap bitmap) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 0, outputStream); return outputStream.toByteArray(); }
From source file:Main.java
public static byte[] bitmapToBytes(Bitmap bitmap) { if (bitmap == null) return null; final ByteArrayOutputStream os = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); return os.toByteArray(); }