我试图将捕获的.bmp文件保存到SD卡。 这里的代码片段,其中负责此:Android保存bmp图像
String root = Environment.getExternalStorageDirectory().toString();
File mFolder = new File(root + "/mFolder");
if (!mFolder.exists())
{
mFolder.mkdir();
}
String strF = mFolder.getAbsolutePath();
File mSubFolder = new File(strF + "/MyApp-SubFolder");
if (!mSubFolder.exists())
{
mSubFolder.mkdir();
}
String s = "myfile.png";
File f = new File(mSubFolder.getAbsolutePath(),s);
String strMyImagePath = f.getAbsolutePath();
FileOutputStream fos = null;
try
{
fos = new FileOutputStream(f);
bmp.compress(Bitmap.CompressFormat.PNG,70, fos);
fos.flush();
fos.close();
Log.d("asd", "yeah!");
// MediaStore.Images.Media.insertImage(getContentResolver(), b, "Screen", "screen");
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
但有一个错误:
images are invalid and its size are 0kb
我在做什么错?
一个String = “myfile.png”; ?你说该文件是.BMP – Hasham 2013-04-05 13:03:58
试试这个\t文件storagePath =新的文件( \t \t \t \t \t Environment.getExternalStorageDirectory()+ “/ MyApp的子文件夹中/”); – Hasham 2013-04-05 13:06:02