0
votes

Well, I'm resizing an image in VB.NET. I have predefined algorithm that converts the image into particular size.

I just found a bug in the algorithm which causes white linings on right side of the image. After debugging the code i found that,

Dim grReturn As Drawing.Graphics = Drawing.Graphics.FromImage(bmpReturn)    
grReturn.Clear(Color.White)

causes the issue. I tried googling the issue and found just a single MSDN link which says it clears the entire drawing surface and fills it with the specified background color.

And i am not able to understand what it says!

I am able to remove white linings from my output image by commenting this Clear function. As i don't know what this function actually does, i can not remove it.

So if anyone could help me understanding the method? Will it cause any other issue if i remove this method?

Thanks!

1
The explanation you are posting sounds pretty descriptive: it sets the background of the graphic (future image) to the given color. From what you are saying, your problem is not provoked because this code "draws lines", but because it makes the whole background white and the size of bmpReturn does not occupy all this background (and thus the white lines you see are not more than parts of the background). If you don't want this effect, just don't use this line of code; and, in general, you shouldn't use code whose exact functionality is not clear to you. - varocarbas
@varocarbas Yes i agree! So let me remove the line of code and test is properly. And as i said, algorithm was already developed, i have no idea why 'Clear' method was used. You did a good help! Thanks! - jparthj
No problem. Clear() does nothing irreplaceable (if you don't want the background colour); just creating a new Graphics objects would also do the job. - varocarbas
@braX: Are you really going to edit all 600 questions with clear in it? Could you at least add a link to a Meta discussion in the edit description? This type of action is usually coordinated... - Cris Luengo
Oh.. I was not aware of Meta discussions. It "clearly" says "do not use" in all caps even.. I was trying to help out. - braX

1 Answers

0
votes

Clear method simply draws the background of the graphics to the provided color code.

As per Varocarbas comment above question,

"The explanation you are posting sounds pretty descriptive: it sets the background of the graphic (future image) to the given color. From what you are saying, your problem is not provoked because this code "draws lines", but because it makes the whole background white and the size of bmpReturn does not occupy all this background (and thus the white lines you see are not more than parts of the background). If you don't want this effect, just don't use this line of code; and, in general, you shouldn't use code whose exact functionality is not clear to you"