WinForms gives us the PictureBox control, into which we can easily load images of different formats, have them scaled for us, etc.
But, unfortunately, PictureBox gives us no obvious way to paint it ourself via some SetPixel method.
In this article i will thus show you how to implement your own SetPixel method. As you will know, when you directly execute a long-running function, the user interface will be unresponsive (you won't be able to move the window, or click anything on it) until the function has finished running. When painting something, your paint method might be very long running (for example if you do raytracing), so we will do our painting in a background thread. This will only add a few lines of code, but keep the application running smooth.
Also, since there are different ways to achieve our goals, i will split this article up into two parts, showing you different methods of how to achieve the same effect.
For the rest of this article, i assume that we have a Windows Forms project, and that the form contains a PictureBox named pictureBox1, and a Button (named button1), which will start our test-rendering.