Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.Context;
- import android.content.ContextWrapper;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import static openaccount.laxmi.app.log.Logger.LOGD;
- import static openaccount.laxmi.app.log.Logger.makeLogTag;
- /**
- * Created by mubin on 4/24/16.
- */
- public class ImageSaver {
- private static final String TAG = makeLogTag(ImageSaver.class);
- /**
- * Methos to save the bitmap to the internal memory
- * @param image : bitmap image to save
- * @param accountNumber : account number
- * @param context
- * @param imageType : type of image. Please check constant.java
- * @return
- */
- public static String storeImage(Bitmap image, String accountNumber, Context context, Integer imageType) {
- ContextWrapper cw = new ContextWrapper(context);
- // path to /data/data/yourapp/app_data/imageDir
- // if folder is not present it will be created automatically
- File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
- String fileName = getFileName(accountNumber, imageType);
- File mypath=new File(directory,fileName);
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(mypath);
- // Use the compress method on the BitMap object to write image to the OutputStream
- image.compress(Bitmap.CompressFormat.PNG, 100, fos);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- fos.close();
- } catch (IOException e) {
- LOGD(TAG, "Cannot close the stream");
- }
- }
- return directory.getAbsolutePath();
- }
- private static String getPrefixFileName(Integer imageType) {
- switch (imageType){
- case 0:
- return "right_thumb";
- case 1:
- return "left_thumb";
- case 2:
- return "citizenship";
- case 3:
- return "passport";
- case 4:
- return "license";
- case 5:
- return "profile";
- case 6:
- return "signature";
- default:
- return null;
- }
- }
- /**
- * Every account Number will have at most 7 images.
- * Each and every file should be unique.
- *
- *
- * @param accountNumber
- * @param imageType
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement