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保存为图像