Store Bitmap image to SD Card in Android

前端 未结 3 1105
鱼传尺愫
鱼传尺愫 2021-01-05 19:01

I am facing some strange problem with my android code, I have an image in Bitmap variable and want to save that file to SD card. I code as follow,

Bitmap IMA         


        
3条回答
  •  渐次进展
    2021-01-05 19:21

    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
            //4
            File file = new File(Environment.getExternalStorageDirectory()+File.separator +        "image.jpg");
            try {
                file.createNewFile();
                FileOutputStream fo = new FileOutputStream(file);
                //5
                fo.write(bytes.toByteArray());
                fo.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    

提交回复
热议问题