List of usage examples for android.util Base64 DEFAULT
int DEFAULT
To view the source code for android.util Base64 DEFAULT.
Click Source Link
From source file:Main.java
public static String convertBitmapToString(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos); byte[] b = baos.toByteArray(); String temp = null;//ww w.j a va2 s. c o m try { System.gc(); temp = Base64.encodeToString(b, Base64.DEFAULT); } catch (Exception e) { e.printStackTrace(); } catch (OutOfMemoryError e) { baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos); b = baos.toByteArray(); temp = Base64.encodeToString(b, Base64.DEFAULT); } return temp; }
From source file:Main.java
public static String openAsBase64(String imgPath) { Bitmap photo = BitmapFactory.decodeFile(imgPath); ByteArrayOutputStream baos = new ByteArrayOutputStream(); photo.compress(Bitmap.CompressFormat.JPEG, 85, baos); byte[] b = baos.toByteArray(); photo.recycle();//from ww w. jav a2s . c o m return Base64.encodeToString(b, Base64.DEFAULT); }
From source file:Main.java
/** * This method converts bitmap to base64 string. * //from ww w. jav a2s . c o m * @param bitmap * @return base64EncodedImage */ public static String encodeTobase64(Bitmap bitmap) { // TODO Auto-generated method stub ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] b = baos.toByteArray(); return Base64.encodeToString(b, Base64.DEFAULT); }
From source file:Main.java
@SuppressLint("NewApi") public static String getBitmapStrBase64(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 100, baos); byte[] bytes = baos.toByteArray(); String data = Base64.encodeToString(bytes, 0, bytes.length, Base64.DEFAULT); if (bitmap != null) { bitmap.recycle();//from w w w.jav a 2 s .c o m bitmap = null; } return data; }
From source file:Main.java
public static String convertToBase64(Bitmap bmp) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 80, stream); byte[] byteArray = stream.toByteArray(); try {//from w w w . j av a2 s . co m stream.close(); } catch (IOException e) { e.printStackTrace(); } return Base64.encodeToString(byteArray, Base64.DEFAULT); }
From source file:Main.java
public static String bitmapToString(String filePath) { Bitmap bm = getSmallBitmap(filePath); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(CompressFormat.JPEG, 40, baos); byte[] b = baos.toByteArray(); return Base64.encodeToString(b, Base64.DEFAULT); }
From source file:Main.java
public static String createHMACWithMD5(String source, String key) throws NoSuchAlgorithmException, InvalidKeyException { Mac hmac = Mac.getInstance("HmacMD5"); SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), hmac.getAlgorithm()); hmac.init(secretKey);/* w w w. jav a 2s . co m*/ byte[] signature = hmac.doFinal(source.getBytes()); return Base64.encodeToString(signature, Base64.DEFAULT); }
From source file:Main.java
public static String setImBin(String fName) { FileInputStream fileInputStream = null; File file = new File(Environment.getExternalStorageDirectory().getPath(), "Pictures/" + fName); byte[] bFile = new byte[(int) file.length()]; try {//from www . j ava2 s. c o m fileInputStream = new FileInputStream(file); fileInputStream.read(bFile); fileInputStream.close(); } catch (Exception e) { e.printStackTrace(); } return Base64.encodeToString(bFile, Base64.DEFAULT); }
From source file:Main.java
public static String objectToString(Serializable object) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try {/*from w ww . ja v a 2s.c o m*/ new ObjectOutputStream(out).writeObject(object); byte[] data = out.toByteArray(); out.close(); out = new ByteArrayOutputStream(); Base64OutputStream b64 = new Base64OutputStream(out, Base64.DEFAULT); b64.write(data); b64.close(); out.close(); return new String(out.toByteArray()); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * Decodes a Base64 string into a Bitmap. Used to decode Bitmaps encoded by * {@link encodeBitmapAsString(Bitmap)}. * @param encodedString the Base64 String to decode. * @return the Bitmap which was encoded by the String. */// w w w . j av a 2 s . c o m public static Bitmap decodeBitmapFromString(String encodedString) { if (TextUtils.isEmpty(encodedString)) return null; byte[] decoded = Base64.decode(encodedString, Base64.DEFAULT); return BitmapFactory.decodeByteArray(decoded, 0, decoded.length); }