Viewing Bitmap(s) While Debugging

Nathan Sokalski 4,111 Reputation points
2023-03-02T02:34:33.82+00:00

I have a number of Android.Graphics.Bitmap(s) that I create, use & modify in my app. In most cases, the Bitmap is modified in multiple ways in the same method/function, so setting it as the source of an ImageView (for debugging purposes) would not work, since it would be modified again before the UI was updated. Is there any good way to examine a Bitmap while debugging, or a simple way to temporarily save it to a local file on my machine (without needing to mess around with permissions & other stuff)?

Developer technologies .NET Xamarin
Developer technologies .NET Other
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-03-02T07:26:30.12+00:00

    Hello,

    Is there any good way to examine a Bitmap while debugging, or a simple way to temporarily save it to a local file on my machine (without needing to mess around with permissions & other stuff)?

    Depending on your Android's storage permission settings, you can stage the bitmaps you need to the app's internal storage, which doesn't require any additional permissions.

    Please refer to the following code sample and File Storage and Access with Xamarin.Android to get more details:

    var bmp = BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.abc_ab_share_pack_mtrl_alpha);
    var backingFile = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "test2.png");
    FileStream fs = System.IO.File.OpenWrite(backingFile);
    bmp.Compress(Bitmap.CompressFormat.Png, 100, fs);
    fs.Flush();
    fs.Close();
    Toast.MakeText(this, "success!", ToastLength.Long).Show();
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


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.