How to Save bitmap to `Pictures`?

mc 5,426 Reputation points
2021-07-02T06:02:38.593+00:00

in xamarin.android I have an Android.Graphics.Bitmap and how to save it to the Pictures?

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,971 Reputation points
    2021-07-05T06:16:25.207+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    I have an Android.Graphics.Bitmap and how to save it to the Pictures

    To save the bitmap to Android storage, you could create a FileStream object with the path and then call the Bitmap.Compress method to generate the picture.

    Check the code:

       var folder = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;  
       var filePath = System.IO.Path.Combine(folder, "test.png");  
       var stream = new FileStream(filePath, FileMode.Create);  
         
       //get the bitmap  
         
       bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);  
       stream.Close();  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.