Reputation: 3276
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.
Upvotes: 1
Views: 8750
Reputation: 81610
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");
}
Upvotes: 1
Reputation: 3276
Correct me if I am wrong.
Coming from Delphi win32, I know you can create an object of a bitmap and set its image property later as follows.
Bitmap:TBitmap;
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile('c:\example.bmp');
In that case, you can't just check to see if Bitmap object is null or nil. You need to actually check if the image property is set or empty.
As far as .NET, when you create an object of a bitmap, you have to pass in the image as a parameter to its constructor. That means constructor instantiates and sets its image. You could check if the image resolution or width and height is set or not like Henk Holterman pointed out.
image1 = new Bitmap(@"C:\Documents and Settings\All Users\Documents\My Music\music.bmp", true);
Upvotes: 0