Search code examples
vb.netwinformsdrawingpicturebox

How to change the size of the pixel in setPixel Function?


I want to change the size of the pixel in setPixel Function.

When I use setPixel Function. It drew a pixel. But it is very small.

Is there a way to change the size of the pixel in setPixel Function ?

I Remember in VB6 , There was a property in the properties of PictureBox called DrawWidth. In this property I can change the size of the drawing.

Maybe I have to use this property in VB.NET. But I did not find it in the properties of PictureBox in VB.NET.


Solution

  • A quick option is to scale up a smaller image

    'draw a small bitmap 
    Dim bmp = New Bitmap(25, 25)
    For y = 0 To 24
      For x = 0 To 24
        If x = y Then
          bmp.SetPixel(x, y, Color.Red)
        End If
      Next x
    Next y
    'scale it up 4x
    Dim bmpBigger = New Bitmap(bmp, 100, 100)
    PictureBox1.Image = bmpBigger
    

    Output might be a bit fuzzy, though. To get exactly what you want you will need to use Graphics class