Click here to Skip to main content
15,746,534 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a barcode using Zxing.
But what I want is that I want to throw the picture into a stack panel in wpf.
How do I throw it into the Stackpanel?

result.Save(DateTime.Now.Ticks + ".JPEG");
this image is debug folder.But I want to create C destination and this image is wpf stackpanel put it.How to done image put it stackpanel.

1 stackpanel should be split in two.I want to place the image in the other pane.

What I have tried:

for (int x = 0; x < matrix.Height; x++)
            for (int y = 0; y < matrix.Width; y++)
                Color pixel = matrix[x, y] ? Color.Black : Color.White;
                for (int i = 0; i < s; i++)
                for (int j = 0; j < s; j++)
                    result.SetPixel(x * s + i, y * s + j, pixel);

result.Save(DateTime.Now.Ticks + ".JPEG");
Updated 1-Aug-19 12:48pm
Gerry Schmitz 2-Aug-19 3:19am    
StackPanel.Children.Add( frameworkElement );

1 solution

If you have saved the image as a file, then you can just use the Image control of WPF framework and have it rendered for you, Image Class (System.Windows.Controls) | Microsoft Docs[^]

The Image control - The complete WPF tutorial[^]

Now for the second part of your question,
I want to create C destination
Then change the path for the image, to something like this,
// Assuming that Images folder does exist. 
result.Save("C:\\Images\\" + DateTime.Now.Ticks + ".JPEG");
This will create the image in that folder, then you can use the same file and show it in the WPF. One thing to notice here is that after this code executes you will miss the value for DateTime.Now.Ticks, so better to store it as a variable.
var ticks = DateTime.Now.Ticks; 
var path = $@"C:\Images\{ticks}.JPEG";

// Show the image in WPF using the path variable as source. 
You can read how to set the source for an Image control in the link I provided above.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900