如何获取使用 FileOutputStream 保存的文件的 URI?
How do I get the URI of a file saved with FileOutputStream?
这是将图像文件保存到...某处的代码?如何获取文件 "webimage" 的 URI?
Bitmap bmp = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
String fileName = "webImage";//no .png or .jpg needed
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
FileOutputStream fo = openFileOutput(fileName, Context.MODE_PRIVATE);
fo.write(bytes.toByteArray());
// remember close file output
fo.close();
} catch (Exception e) {
e.printStackTrace();
}
您可以使用 Uri.fromFile(imageFile)
,其中 imageFile
是 File
的一个实例
我想明白了:
final File file = new File(getFilesDir(), "webImage");
Uri weburi = Uri.fromFile(file);
像这样使用getFileStreamPath():
String fileName = "webImage";
//...
Uri uri = Uri.fromFile(getFileStreamPath(fileName));
这是将图像文件保存到...某处的代码?如何获取文件 "webimage" 的 URI?
Bitmap bmp = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
String fileName = "webImage";//no .png or .jpg needed
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
FileOutputStream fo = openFileOutput(fileName, Context.MODE_PRIVATE);
fo.write(bytes.toByteArray());
// remember close file output
fo.close();
} catch (Exception e) {
e.printStackTrace();
}
您可以使用 Uri.fromFile(imageFile)
,其中 imageFile
是 File
我想明白了:
final File file = new File(getFilesDir(), "webImage");
Uri weburi = Uri.fromFile(file);
像这样使用getFileStreamPath():
String fileName = "webImage";
//...
Uri uri = Uri.fromFile(getFileStreamPath(fileName));