Capturing and Saving an image in Android with different names and then retrieving it by any of those names?

末鹿安然 提交于 2020-04-21 04:34:54

问题


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.

  1. Is it good to store the images in SQLlite or External Memory

  2. Can I store the image with multiple comma separated names in sqllite and then retrieve it as per those names.

For e.g. I have a capture button where I can click to capture an image and then if the image is okay i can press next where it shows me a text box and save button. In the text box I can enter multiple names of image say - x1, x2, x3 etc. and then i want to retrieve the image by using any of these names.

any good idea will be much appreciated.


回答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

public static 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())
            return null;
        try {
            FileOutputStream out = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
            out.flush();
            out.close();
            return file;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

I hope that it will be usefull for you



来源:https://stackoverflow.com/questions/32713542/capturing-and-saving-an-image-in-android-with-different-names-and-then-retrievin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!