Convert Android.Graphics.Bitmap to Image

后端 未结 2 1184
礼貌的吻别
礼貌的吻别 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;
     }
    
    0 讨论(0)
  • 2020-12-19 05:42
    Bitmap bm = BitmapFactory.DecodeFile (path);
    MemoryStream stream = new MemoryStream ();
    bm.Compress (Bitmap.CompressFormat.Jpeg, 100, stream);
    Image img = Image.FromArray (stream.ToArray());
    
    0 讨论(0)
提交回复
热议问题