我试着将照片保存到SD卡和htc设备上,一切正常。我在SD卡上看到了我的照片,当我打开的时候,我看到了我的照片。但当我在galaxy标签上尝试时,照片被保存了,但当我打开这张照片时,我只看到了黑屏。有谁能告诉我如何修复它吗?
我的代码
tempBMP.compress(Bitmap.CompressFormat.JPEG, 85, stream);
log("stream3");
File saveDir=null;
String filename="";
byte[] byteArray = stream.toByteArray();
try
{
if (!saveDir.exists())
{
saveDir.mkdirs();
}
FileOutputStream os = new FileOutputStream(String.format("/sdcard/ "+""+filename, System.currentTimeMillis()));
os.write(byteArray);
os.close();
}
catch (Exception e)
{
} 打招呼,彼得。
发布于 2011-07-25 17:13:14
我真的不知道为什么,但这段代码对我来说是有效的。也许你应该使用Enviroment.getExternalStorageDirectory()而不是"/sdcard/“。试试看。
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath());
dir.mkdirs();
File out = new File(dir,filename);
try {
out.createNewFile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
DataOutputStream fo = null;
try {
fo = new DataOutputStream( new FileOutputStream(out));
//write what you want to fo
fo.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}发布于 2011-07-25 17:09:46
是的,这是Galaxy Tab本身的问题,我认为如果图像不在默认的图像文件夹中,则无法查看,如果您将SDCard安装在PC上,则可以很容易地查看这些图像。
所以总体的想法是你的图像没有被损坏,只是Galaxy Tab的问题
发布于 2011-07-25 17:15:59
我猜你的代码抛出了空指针异常,你通常在catch块中处理它,而不做任何事情来处理它。看一看。可以使用Enviroment.getEternalStorageDirectory()获取SD卡目录的根目录。
https://stackoverflow.com/questions/6813447
复制相似问题