【发布时间】:2012-11-03 17:47:41
【问题描述】:
我试图将我的应用程序资源中的实际图像保存到 SD 卡上的文件中,以便消息传递应用程序可以访问它,但我收到错误 - FileOutputStream 类型中的方法 write(byte[])不适用于参数(可绘制) - 它应该保存它。我相信我没有使用适当的方法来保存实际图像本身,而且我很难找到解决方案。
// Selected image id
int position = data.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ChosenImageView.setImageResource(imageAdapter.mThumbIds[position]);
Resources res = getResources();
Drawable drawable = res.getDrawable(imageAdapter.mThumbIds[position]); //(imageAdapter.mThumbIds[position]) is the resource ID
try {
File file = new File(dataFile, FILENAME);
file.mkdirs();
FileOutputStream fos = new FileOutputStream(file);
fos.write(drawable); // supposed to save the image here, getting the error at fos.write
fos.close();
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
【问题讨论】: