Hello.
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!
views:
187answers:
3
+1
A:
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.
Mark Heath
2009-11-05 10:55:59
+2
A:
You've got three options:
- Add a 1 pixel sized rectangle to a Canvas (the canvas is how you do co-ordinate position in WPF),
- Do some custom painting in a WriteableBitmap (examples are at that page)
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)); }
Rob Fonseca-Ensor
2009-11-05 10:59:37
The code snippet isn't clear about what type `visual` is. That got me stuck trying to Google more info about this, because the base `Visual` class doesn't have a `RenderOpen` method. It looks like it has to be of type `DrawingVisual`.
Joe White
2010-09-02 13:06:01
A:
You can use a Shape object like Line or Rectangle in XAML or in code.
For example using Line in XAML you could use
<Line X1="10"
Y1="10"
X2="11"
Y2="11"
Stroke="Black"
StrokeThickness="1" />
X1 is the begin x coordinate. X2 is the end x coordinate. Y1 is the begin y coordinate. Y2 is the end y coordinate.
RonaldV
2009-11-05 11:19:23