Skip to content Skip to sidebar Skip to footer

Capturing And Saving An Image In Android With Different Names And Then Retrieving It By Any Of Those Names?

I am new to android and have managed to run my app where I can use the camera to capture the image. However I want to know the best solution to store and retrieve the images. Is i

Solution 1:

I think best way to store your Images is to save it on External memory. This way is also simplest way!

Here you are some pice of code to save the image on external

publicstatic File saveImage(Bitmap bitmap, String imageName) {
        File myDir = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES), DIR);

        if (!myDir.mkdirs()) {
            Log.e(ImageUtils.class.getSimpleName(), "Directory not created");
        }

        myDir.mkdirs();
        String image = getImageName(imageName);
        File file = new File(myDir, image);

        if (file.exists())
            returnnull;
        try {
            FileOutputStream out = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
            out.flush();
            out.close();
            return file;
        } catch (Exception e) {
            e.printStackTrace();
            returnnull;
        }
    }

I hope that it will be usefull for you

Post a Comment for "Capturing And Saving An Image In Android With Different Names And Then Retrieving It By Any Of Those Names?"