about uscontact

Store image to file

Author: zemna
Date: April 17, 2021
Share this:

[code lang="java"] public static boolean StoreByteImage(Context mContext, byte[] imageData, int quality, String expName) {

File sdImageMainDirectory = new File("/sdcard/myImages"); FileOutputStream fileOutputStream = null; String nameFile; try {

BitmapFactory.Options options=new BitmapFactory.Options(); options.inSampleSize = 5;

Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length,options);

fileOutputStream = new FileOutputStream( sdImageMainDirectory.toString() +"/" + nameFile + ".jpg");

BufferedOutputStream bos = new BufferedOutputStream( fileOutputStream);

myImage.compress(CompressFormat.JPEG, quality, bos);

bos.flush(); bos.close();

} catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }

return true; } [/code]

Share this:

Leave a Reply

Your email address will not be published.


Professional software development agency estalished in Indonesia. We offers website setup, web application development, fulfillment service, and etc.
Follow us
Follow us to get latest news and tutorials.
2022 - Copyright, All Rights Reserved, Made by ZEMNA.NET with ❤️