List of usage examples for android.graphics BitmapFactory decodeByteArray
public static Bitmap decodeByteArray(byte[] data, int offset, int length)
From source file:Main.java
/** * This method converts base64 string to bitmap. * //from www . ja v a 2 s .c om * @param base64EncodedImage * @return bitmap */ public static Bitmap decodeFromBase64(String base64EncodedImage) { try { byte[] b = Base64.decode(base64EncodedImage, 0); return BitmapFactory.decodeByteArray(b, 0, b.length); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); return null; } }
From source file:Main.java
public static Bitmap convertStringToBitmap(String st) { // OutputStream out; Bitmap bitmap = null;/*from www .j a v a 2 s.c o m*/ try { // out = new FileOutputStream("/sdcard/aa.jpg"); byte[] bitmapArray; bitmapArray = Base64.decode(st, Base64.DEFAULT); bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length); // bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); return bitmap; } catch (Exception e) { return null; } }
From source file:Main.java
public static Bitmap convertString2Icon(String st) { // OutputStream out; Bitmap bitmap = null;/* w ww .j a v a 2 s . com*/ try { // out = new FileOutputStream("/sdcard/aa.jpg"); byte[] bitmapArray; bitmapArray = Base64.decode(st, Base64.DEFAULT); bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length); // bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); return bitmap; } catch (Exception e) { return null; } }
From source file:Main.java
public static boolean convertBytes2Bitmap(String imageName, byte[] byt) { if (byt.length == 0) return false; boolean success = true; Bitmap bmp = BitmapFactory.decodeByteArray(byt, 0, byt.length); File file = new File("/sdcard/" + imageName + ".png"); try {/*w w w . j ava 2 s . c o m*/ file.createNewFile(); } catch (IOException e) { success = false; } FileOutputStream out = null; try { out = new FileOutputStream(file); } catch (FileNotFoundException e) { success = false; } bmp.compress(Bitmap.CompressFormat.PNG, 100, out); try { out.flush(); } catch (IOException e) { success = false; } try { out.close(); } catch (IOException e) { } return success; }
From source file:Main.java
public static Bitmap bitmap(String uri) { byte[] imageData = toByteArray(uri); if (imageData != null) { Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length); return bitmap; }/*from w ww . j a v a 2s . c om*/ return null; }
From source file:Main.java
/** * Converts the supplied byte[] to a Bitmap at 75% compression * * @param bytes the bitmap's bytes//from w w w . jav a 2 s . c o m * @return the Bitmap */ public static synchronized Bitmap asBitmap(byte[] bytes) { Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); return Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 4, bmp.getHeight() / 4, true); }
From source file:Main.java
public static Bitmap scaleToStretchBitmap(Bitmap dst, byte[] byImage) { Bitmap src = BitmapFactory.decodeByteArray(byImage, 0, byImage.length); return Bitmap.createScaledBitmap(src, dst.getWidth(), dst.getHeight(), true); }
From source file:Main.java
public static void base64ToBitmap(String base64Data, String imgName, String imgFormat) { byte[] bytes = Base64.decode(base64Data, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); File myCaptureFile = new File("/sdcard/", imgName); FileOutputStream fos = null;/*w w w .java2 s . c om*/ try { fos = new FileOutputStream(myCaptureFile); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } boolean isTu = bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); if (isTu) { // fos.notifyAll(); try { fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } } else { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
/** * Decodes a base-64 byte array representation into a Bitmap. Call the * setImageBitmap method on an ImageView with the returned Bitmap object. * * @param data the raw base-64 image data * @return the converted Bitmap that can be used as an ImageView source *///from w w w. j a v a 2 s . co m public static Bitmap decodeBase64Image(byte[] data) { return BitmapFactory.decodeByteArray(data, 0, data.length); }
From source file:Main.java
public static Bitmap byteToBitmap(byte[] byteArray) { if (byteArray.length != 0) { return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); } else {//from w w w . j a v a 2s.c o m return null; } }