Viewing Bitmap(s) While Debugging

Nathan Sokalski 4,116 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)?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,368 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 35,291 Reputation points Microsoft Vendor
    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.