none
Question about turning on a pixel RRS feed

  • Question

  • In vb6 there use to be a function PSET that allowed you to select a particular pixel at an x-y coordinate and change the color of it. I have tried using vb.net to find an equivalent way of doing it and the best I have found so far is using the ellipse and setting its height and width to 1?? Is this my only available option? Any feedback would be helpful.

    Thanks,

    Les

    Sunday, November 4, 2018 9:21 PM

Answers

  • Hi

    Here is some quick and dirty pixel editing.

        Dim bm As New Bitmap(Image.FromFile("C:\Users\lesha\Desktop\Plans\Dice 2\62.png"))
    
        For i As Integer = 10 To 30
          For j As Integer = 20 To 40
            bm.SetPixel(i, j, Color.Red)
    
          Next
        Next
    
        PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
        PictureBox1.Image = bm


    Regards Les, Livingston, Scotland


    • Edited by leshay Sunday, November 4, 2018 9:57 PM
    • Marked as answer by Les2011 Wednesday, August 7, 2019 4:11 AM
    Sunday, November 4, 2018 9:56 PM

All replies

  • Hi

    Here is some quick and dirty pixel editing.

        Dim bm As New Bitmap(Image.FromFile("C:\Users\lesha\Desktop\Plans\Dice 2\62.png"))
    
        For i As Integer = 10 To 30
          For j As Integer = 20 To 40
            bm.SetPixel(i, j, Color.Red)
    
          Next
        Next
    
        PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
        PictureBox1.Image = bm


    Regards Les, Livingston, Scotland


    • Edited by leshay Sunday, November 4, 2018 9:57 PM
    • Marked as answer by Les2011 Wednesday, August 7, 2019 4:11 AM
    Sunday, November 4, 2018 9:56 PM
  • Hey Les how are you?  Thanks so much for the feedback I will play with it later.

    Thanks,

    Les

    Sunday, November 4, 2018 10:17 PM
  • Hi Les

    I played around with the SetPixel but I did not see any change to the pixel that I was targeting.  I wonder if it is because I am not using a bmp picture??  I have a picturebox that I draw to and then work on the buffer associated with it.  Perhaps this SetPixel only works on a bitmap image?? Just a guess.  I will check the forum out in the morning to see if you remarked about this.

    Thanks

    Les

    Monday, November 5, 2018 7:04 AM
  • Hi Les

    I played around with the SetPixel but I did not see any change to the pixel that I was targeting.  I wonder if it is because I am not using a bmp picture??  I have a picturebox that I draw to and then work on the buffer associated with it.  Perhaps this SetPixel only works on a bitmap image?? Just a guess.  I will check the forum out in the morning to see if you remarked about this.

    Thanks

    Les

    Hi,

    see the following link

    https://docs.microsoft.com/en-us/dotnet/api/system.drawing.bitmap.setpixel?redirectedfrom=MSDN&view=netframework-4.7.2

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 5, 2018 8:27 AM
  • Hi Les

    I played around with the SetPixel but I did not see any change to the pixel that I was targeting.  I wonder if it is because I am not using a bmp picture??  I have a picturebox that I draw to and then work on the buffer associated with it.  Perhaps this SetPixel only works on a bitmap image?? Just a guess.  I will check the forum out in the morning to see if you remarked about this.

    Thanks

    Les

    Hi

    Well, what can I say. It is difficult to see one pixel amongst many thousand (possibly). Try setting a small 'grid' of pixels (as per my example) just to see the initial change.


    Regards Les, Livingston, Scotland

    Monday, November 5, 2018 12:22 PM
  • Good thought and idea.  I will give that a try.  BTW when I work with the

    DrawEllipse method and set the height and width to 1 I can see it lights up just one pixel so although difficult I can see one pixel but maybe its larger then 1 pixel.  But I will try your method and make a slightly larger area and see what happens.

    THanks

    Les

    Monday, November 5, 2018 5:40 PM
  • Hi Alex I actually have been to your link but it does not mention if SetPixel needs an image to work on like my post was asking.  But thanks for the link

    Les

    Monday, November 5, 2018 5:42 PM
  • Hi Alex I actually have been to your link but it does not mention if SetPixel needs an image to work on like my post was asking.  But thanks for the link

    Les


    Yes SetPixel only works to set a color on a bitmap.

    There is no pset equal. If you are drawing on a graphic surface like the one provided with e.graphics in a paint event, then you need to draw a graphics shape and yes drawellipse is ok. It is affected by the line width and style. Also just fillellipse. Then a 1 pixel something is affected by the smoothing mode as well.

    Monday, November 5, 2018 5:54 PM
  • Hi TTT

    Thanks so much for your answer to my post.  That's what I started to think <S>.  Listen one other question if this is permitted of course.  If I have a picturebox that I am drawing to the coordinate system I totally understand but here is my delema.  If I set up a x-y axis inside and say the picturebox is 500x500 pixels I set up a nice grid like graph paper.  If I need to draw a line in the form of y=mx+b if I can change the internal coordinates like I use to be in vb6 using the viewport that was exactly what I would like to have here in vb.net.  That would allow me to if I have a line that is say has an x that goes to 10 and y is 10 then the line looks to small.  In that case I can set my viewport to maybe 30x30 and it would look much bigger on the picturebox but it also gives me the flexability that if my line or any other function is say 300x300 I would  like to set up the viewport to slightly larger then that??  I hope I am explaining this properly <S>. I know from the past you seem to be a big graphics freak <S>.

    If I am suppose to repost this question then let me know.

    Thanks

    Les



    • Edited by Les2011 Monday, November 5, 2018 8:25 PM
    Monday, November 5, 2018 8:02 PM
  • Hi TTT

    Thanks so much for your answer to my post.  That's what I started to think <S>.  Listen one other question if this is permitted of course.  If I have a picturebox that I am drawing to the coordinate system I totally understand but here is my delema.  If I set up a x-y axis inside and say the picturebox is 500x500 pixels I set up a nice grid like graph paper.  If I need to draw a line in the form of y=mx+b if I can change the internal coordinates like I use to be in vb6 using the viewport that was exactly what I would like to have here in vb.net.  That would allow me to if I have a line that is say has an x that goes to 10 and y is 10 then the line looks to small.  In that case I can set my viewport to maybe 30x30 and it would look much bigger on the picturebox but it also gives me the flexability that if my line or any other function is say 300x300 I would  like to set up the viewport to slightly larger then that??  I hope I am explaining this properly <S>. I know from the past you seem to be a big graphics freak <S>.

    If I am suppose to repost this question then let me know.

    Thanks

    Les



    Hi Les,

    Well what exactly works best depends on exactly how your existing drawing code works now.

    Its like I was trying to say previously when I said you should scale the object to fit the window.

    You can set a graphics viewport using ScaleTransform and TranslateTransform etc. ie:

       e.graphics.ScaleTransform(2,2)

     doubles the window/viewport zoom "magnification".

    I think its better to start a new question if you can come up with a specific question and even example. Get others involved. But sometimes it does not matter.

    See how the example below has a grid that shows the viewport? Zoom with the mouse wheel etc.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/a95ea88e-588f-47c0-b8bc-a3a9fe8a7469/how-to-draw-to-scale-cad-with-gdi-and-vbnet?forum=vbgeneral

    Monday, November 5, 2018 8:41 PM
  • Hi TTT

    Wow that some link you gave me <S> impressive.  I guess from what I see is that using those transforms you mentioned can do the trick.  For the purpose of actually working with a coordinated system I think this is what the doctor ordered but in the previous stuff I was working with was not good.  So basically by using these transforms I can change the coordinate system graphically to what I want and can I assume that I can do that through code??

    BTW I went to the link with your demo and all I can say is involved but very impressive <S>

    I will check out those transform methods and once again thanks

    Les

    Monday, November 5, 2018 8:49 PM