Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I turn on (change color) of a single pixel by coordinates in WPF


I have seen similar questions on here but haven't found an answer.
I'm taking a computer graphics course in college and we are taught different algorithms that are used to display shapes.
My assignment is to choose any development platform and implement these algorithms.
Since I have experience developing in WPF, I want to use it for this assignment.
But I can't seem to find how to give the coordinates of a pixel and change its color.
I know school-related questions aren't so popular here on stackoverflow, but I don't feel that asking this question is cheating on my homework in any way.
Thank you!

like image 753
devdevdev Avatar asked Nov 05 '09 10:11

devdevdev


2 Answers

You've got three options:

  1. Add a 1 pixel sized rectangle to a Canvas (the canvas is how you do co-ordinate position in WPF),
  2. Do some custom painting in a WriteableBitmap (examples are at that page)
  3. Do some custom painting in the CompositionTarget.Rendering event, and "opening" a renderer like so:

    using (DrawingContext context = visual.RenderOpen())
    {
        context.DrawRectangle(Brushes.Red, null, new Rect(5,5,1,1));
    }
    
like image 185
Rob Fonseca-Ensor Avatar answered Nov 16 '22 21:11

Rob Fonseca-Ensor


Try taking a look at the WriteableBitmap class. WPF doesn't let you deal directly with pixels, but the WriteableBitmap will allow you to set pixels on a bitmap and then render it.

like image 39
Mark Heath Avatar answered Nov 16 '22 22:11

Mark Heath