Results 1 to 6 of 6

Thread: painting problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    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
    Last edited by pacerier; Jan 2nd, 2010 at 10:15 PM.

  2. #2
    Addicted Member Mal1t1a's Avatar
    Join Date
    Mar 2008
    Posts
    157

    Re: painting problem


    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    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

  4. #4
    Addicted Member Mal1t1a's Avatar
    Join Date
    Mar 2008
    Posts
    157

    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).

  5. #5
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    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

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: painting problem

    wow that explains alot why its behaving this way

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width