简体   繁体   中英

How to draw a pixel in WPF

I'm sorry for asking such a simple question but this is driving me nuts.

I'm writing in C#, WPF and all I need to do is draw a pixel at location x,y of a specific RGB value.

What I'm running afoul of is the namespaces to use, the dlls to reference, etc. Any code I find throws a ton of compile errors.

So just something short and sweet that will place a dot of RGB value whatever at a specific x,y coordinate in the window would really make my day.

Please include the entire example code that will compile, link and run in Visual Studio 2010. Like I said, all the code snippets I've found throw a ton of errors (everything from ambiguous 'Brush' to... well, you name it). And, yes, I'm just starting to write in WPF.

Thanks in advance!


This is for Surfbutler:

Here's an example (right from here: http://msdn.microsoft.com/en-us/library/ms747393.aspx ):

// Add a Line Element
myLine = new Line();
myLine.Stroke = System.Windows.Media.Brushes.LightSteelBlue;
myLine.X1 = 1;
myLine.X2 = 50;
myLine.Y1 = 1;
myLine.Y2 = 50;
myLine.HorizontalAlignment = HorizontalAlignment.Left;
myLine.VerticalAlignment = VerticalAlignment.Center;
myLine.StrokeThickness = 2;
myGrid.Children.Add(myLine);           

And it throws errors not knowing what a Line() is..or myGrid (would that be declared in the XAML?

I found the missing assembly WindowsBase.dll! It was buried and I had to browse for it!

Now, I've only got one error left... myGrid does not exist in the current context.

Is this declared in the XAML window? I suspect that it is. But that is in another project. How do I reference it the MainWindow across two projects that exist in the same solution?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM