开发者

galaxy tab : saving photo on sd card problem

i tried save photo to sd card and on htc device all ok . I开发者_高级运维 see my photo on sd card and when open i see my photo. But when i tried it on galaxy tab , photo are saved but when i open this photo i see only black screen. Can any tell how to fix it ?

my code

 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)
        {
        } 

regards, Peter.


I don't really know why, but this code works for me. Maybe you should use Enviroment.getExternalStorageDirectory() rather than use "/sdcard/". Try it.

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();
            }


Yeah that's the issue of Galaxy Tab itself I think an image can't be viewed if its not on default image folder, if you mount your SDCard on PC then you can easily view these images.

So the overall idea is that your image is not corrupted its just issue with Galaxy Tab


I guess your code is throwing null pointer exception which you are handling in catch block generacally and not doing anything to handle it. have a look at it. Can use Enviroment.getEternalStorageDirectory() for getting root for the sdcard dir.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜