.netbitmapdrawingdelphi-prism

Is there a way to check if Bitmap is empty in .NET?


I am trying to check on a bitmap object to see if it either set or empty. It seems .NET doesn't have that function. I've looked in MSDN library site and stackoverflow and there is very little mention of this in relation to .NET. Is there any other way to do that in .NET?

When TBitmaap doesn't contain any image its Empty property is set to True

Any help will be appreciated.


Solution

  • Your only options for a bitmap is that it is instantiated or its null, and from reading the comments and your answer, it's confusing what you are trying to do.

    You really just need to check if the bitmap is null or not, which is, I think, equivalent to the language you are saying, is empty:

    private Bitmap _bmp;
    
    private void button1_Click(object sender, EventArgs e) {
      if (_bmp == null)
        _bmp = new Bitmap(@"c:\example.bmp");
    }
    

    You can make an extension out of it, like this:

    public static class MyExensions {
      public static bool IsEmpty(this Bitmap bitmap) {
        return (bitmap == null);
      }
    }
    

    and that would turn your code into this:

    private void button1_Click(object sender, EventArgs e) {
      if (_bmp.IsEmpty())
        _bmp = new Bitmap(@"c:\example.bmp");
    }