Convert Android.Graphics.Bitmap to Image

后端 未结 2 1201
礼貌的吻别
礼貌的吻别 2020-12-19 04:48

I am trying to get screenshot of the view as follows. I am getting Bitmap and I need to convert it to to Image to add into PDF generator.

using (var screensh         


        
2条回答
  •  别那么骄傲
    2020-12-19 05:38

    You can use this method:

    public Bitmap getScreenshotBmp() {
    
    
        FileOutputStream fileOutputStream = null;
    
        File path = Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    
        String uniqueID = UUID.randomUUID().toString();
    
        File file = new File(path, uniqueID + ".jpg");
        try {
            fileOutputStream = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    
        screenshot.compress(Bitmap.CompressFormat.JPEG, 30, fileOutputStream);
    
        try {
            fileOutputStream.flush();
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return screenshot;
     }
    

提交回复
热议问题