-
painting problem
in the painteventargs of the form, i've got something like this:
Code:
Dim bm As New Bitmap(1, 1)
Dim g As Graphics = Graphics.FromImage(bm)
Me.BackColor = Color.Yellow
g.Clear(Color.Red)
e.Graphics.DrawImage(bm, 0, 0, 100, 100)
i'm getting a very cool gradient effect from red to yellow, but why is that the case? shouldn't the 1x1 portion be totally red? and the remaining pixels be totally yellow?
[edit]
i'm not trying to paint a 1x1 portion in my form, im trying to know why e.Graphics.DrawImage(bm, 0, 0, 100, 100) doesn't draw a 1x1 red portion on my form through the code provided above.
my understanding is that 0,0 specifies the point to draw the image. bm specifies the image actually drawn, which is 1x1 px. and 100,100 specifies the allowed space for the graphics to draw, if this is correct, the first pixel should be red and the remaning 9999 pixels should be yellow but they aren't
-
Re: painting problem
http://www.Mal1t1a.com/Downloads/result.png
Is what I got with your Code. Was this what you were going for?
Also, yes 0,0 tells the program where to draw, and 100,100 tells the program the width and height of the bitmap to draw.
-
Re: painting problem
but the size of the bitmap is 1x1, if we put 100x100 for the space, the first pixel would be red and the remaning 9999 which are not specified, would be yellow right? but why do we get a gradient
-
Re: painting problem
You get a gradient, because it is stretching out the bitmap. If you tried this code with a Regular bitmap, and remove the: "g.clear(color.red)" part, you will see that the bitmap is being stretched (assuming it is smaller than the size specified).
-
Re: painting problem
Hi pacerier, the effect you are getting depends on the Graphics.InterpolationMode. That determines which algorithm GDI+ will use for scaling images up or down. The default interpolation mode, which you are presumably using, smears the available colours out a bit; sometimes it looks OK and sometimes it's a bit messy. The best quality modes blend the colours in a more sophisticated but slower way. If you want to blow up an image to see sharp, square pixels, use InterpolationMode=NearestNeighbor, which is also the quickest.
I doubt if the Framework designers lost much sleep worrying about what would happen if you blow up 1 pixel to 100x100. But now we know:).
bye, BB
-
Re: painting problem
wow that explains alot why its behaving this way