Question

Is there any function in C# that I can use to show the snapshot directly taken in the picture box? So when I click the button 'Snapshot' not only the image should be saved in my hard drive but also it should be directly shown in a picture box in the same WPF application.

EDIT: this is my code which pretty well works:

private void button1_Click(object sender, RoutedEventArgs e)
{
 BitmapEncoder encoderIR = new PngBitmapEncoder();
 encoderIR.Frames.Add(BitmapFrame.Create(this.colorBitmapIR));
 string myPhotosIR = "C:/...../Visual Studio 2010/Projects/Basic1/Basic1/Resources";
 string pathIR = System.IO.Path.Combine(myPhotosIR, "KinectSnapshotIR.png");
 try
 {
  using (FileStream fsIR = new FileStream(pathIR, FileMode.Create))
  {
   encoderIR.Save(fsIR);
   {
    BitmapImage snapIR = new BitmapImage();
    snapIR.BeginInit();
    snapIR.StreamSource = fsIR;
    snapIR.CacheOption = BitmapCacheOption.OnLoad;
    snapIR.EndInit();
    imageIR.Source = snapIR;
   }
  }
 }
}
Était-ce utile?

La solution

If you are using a Bitmap (I don't recommend because it is much more efficient to use WriteableBitmap) you could set the image directly to it using:

picturebox.Image = bitmap;

Or use the path you just created the image at to show it:

picturebox.Image.FromFile(path);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top