0
所以我正在做的是從另一個應用程序接收數據作爲意圖。我得到的圖像不是嘗試,直到你達到你的輸入流的末尾,將其保存保存圖像Uri作爲圖像
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"))));
}
你的問題不清楚。你究竟在問什麼? – veritas
我希望能夠將Uri作爲圖片保存在我的畫廊中 –