-1

I need to make temp file and then open it with Windows default photo viewer app but I don't know how; Can anyone help me please? I know I can use a PictureBox in a Form but I want my app have the ability to use Windows photo viewer.

int  GridID = Convert.ToInt32(dg_ImageList.CurrentRow.Cells[0].Value);
var query = objDB.Tbl_Image.Find(GridID).Image;
temp file =Image.FromStream(new MemoryStream(query));
Process.Start();
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • 2
    [Get a temp file name](https://learn.microsoft.com/en-us/dotnet/api/system.io.path.gettempfilename?view=net-5.0&WT.mc_id=DT-MVP-5003235) and add the extension of your image to the filename, then [save the bytes](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.writeallbytes?view=net-5.0&WT.mc_id=DT-MVP-5003235) in the file, then pass the filename to [Process.Start](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.start?view=net-5.0&WT.mc_id=DT-MVP-5003235). – Reza Aghaei Jan 04 '21 at 17:14
  • If you do that in my machines, you open up PhotoShop. If you really want to start Windows Photo Viewer, you have to do it *explicitly*. There are some notes here: [Process.Start a file without Extension](https://stackoverflow.com/a/47763682/7444103) that are related to Windows Photo Viewer (well, exactly that, in a section of that post). You have to start `rundll32.exe`, passing the full path of the applet plus its command-line options and the path of the file to open. Then you'll be sure that Windows Photo Viewer is run. -- I'd think about presenting the Images in a GUI of your design. – Jimi Jan 05 '21 at 02:08

1 Answers1

0

Here is my method of doing this:

Private Sub OpenImage(objBinaryImage As Binary)
    Dim ms As New MemoryStream
    ms.Write(objBinaryImage.ToArray(), 0, objBinaryImage.Length)
    Dim objImage As Image = Image.FromStream(ms)
    Dim strSavePath As String = Path.GetTempPath & "Image.png"
    objImage.Save(strSavePath)
    Process.Start(strSavePath)
End Sub

Pass your binary image into this method. The image will be saved to the user temp folder on your computer and will open the image in the default windows image viewer.

AwiringCameron
  • 620
  • 3
  • 18