在移动Android手机上保存图像

时间:2013-03-07 22:45:33

标签: android file-io

我想将从输入流接收的图像保存到设备。 此图像使用ImageView和函数decodeStream()显示。

如何将收到的图像保存到手机上的特定路径(例如,SD卡上)?

2 个答案:

答案 0 :(得分:1)

要保存到外部存储空间,您可以获得如下路径:

Environment.getExternalStorageDirectory().toString();

然后当你启动Camera意图时,使用它,文件位置可以是任何路径。

camera.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, [file location]);

此处有更多信息:http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_OUTPUT

答案 1 :(得分:0)

也从decodestream说一个位图说photo2

 mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
              Environment.DIRECTORY_PICTURES), "your apps name");   

 mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                 "Image" + num + ".png"); // make a int num and save it and
        try {                      //add it to the file name, increment for every
                                     //save that you do
            fOut = new FileOutputStream(mediaFile);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        photo2.compress(Bitmap.CompressFormat.PNG, 100,fOut);