Save bitmap to location

前端 未结 19 2401
悲哀的现实
悲哀的现实 2020-11-22 00:20

I am working on a function to download an image from a web server, display it on the screen, and if the user wishes to keep the image, save it on the SD card in a certain fo

19条回答
  •  迷失自我
    2020-11-22 00:56

    Bitmap bbicon;
    
    bbicon=BitmapFactory.decodeResource(getResources(),R.drawable.bannerd10);
    //ByteArrayOutputStream baosicon = new ByteArrayOutputStream();
    //bbicon.compress(Bitmap.CompressFormat.PNG,0, baosicon);
    //bicon=baosicon.toByteArray();
    
    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
    OutputStream outStream = null;
    File file = new File(extStorageDirectory, "er.PNG");
    try {
        outStream = new FileOutputStream(file);
        bbicon.compress(Bitmap.CompressFormat.PNG, 100, outStream);
        outStream.flush();
        outStream.close();
    } catch(Exception e) {
    
    }
    

提交回复
热议问题