Eth*_*len 4 java android uri android-file
这是将图像文件保存到...某处的代码?如何获取文件“ 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();
}
Run Code Online (Sandbox Code Playgroud)
像这样使用getFileStreamPath():
String fileName = "webImage";
//...
Uri uri = Uri.fromFile(getFileStreamPath(fileName));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4099 次 |
| 最近记录: |