將 res 資原始檔轉換成 file
阿新 • • 發佈:2019-02-01
Bitmap bitmap = BitmapFactory.decodeStream(is);
String defaultPath = getApplicationContext().getFilesDir()
.getAbsolutePath() + "/defaultGoodInfo";
File file = new File(defaultPath);
if (!file.exists()) {
file.mkdirs();
} else {
return;
}
String defaultImgPath = defaultPath + "/messageImg.jpg";
file = new File(defaultImgPath);
try {
file.createNewFile();
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 20, fOut);
is.close();
fOut.flush();
fOut.close();
} catch (Exception e) {
e.printStackTrace();