Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将图像Uri另存为图像_Java_Android_Uri - Fatal编程技术网

Java 将图像Uri另存为图像

Java 将图像Uri另存为图像,java,android,uri,Java,Android,Uri,因此,我正在做的是接收来自另一个应用程序的数据。我正在获取图像,而不是试图保存它 void savefile(Uri sourceuri) { String sourceFilename= sourceuri.getPath(); File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "PhotoSaver")

因此,我正在做的是接收来自另一个应用程序的数据。我正在获取图像,而不是试图保存它

  void savefile(Uri sourceuri)
{
    String sourceFilename= sourceuri.getPath();
    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "PhotoSaver");


    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;

    try {
        bis = new BufferedInputStream(new FileInputStream(sourceFilename));
        bos = new BufferedOutputStream(new FileOutputStream(mediaStorageDir, false));
        byte[] buf = new byte[1024];
        bis.read(buf);
        do {
            bos.write(buf);
        } while(bis.read(buf) != -1);
    } catch (IOException e) {

    } finally {
        try {
            if (bis != null) bis.close();
            if (bos != null) bos.close();
        } catch (IOException e) {

        }
    }

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "PhotoSaver"))));

}

您应该一直阅读,直到到达输入流的末尾,最后刷新输出流。大概是这样的:

     // the file is read to the end
     while ((value = bis.read()) != -1) {
        bos.write(value);
     }

     // invokes flush to force bytes to be written out to baos
     bos.flush();

你的问题不清楚。你到底在问什么?我想在我的图库中将Uri保存为图像