0

I have project with C#. I add picture box control to show images are coming from the database.

I have a DbComand that executes "select * from Client "; and a DataReader to read the results:

byte[] buffer = (byte[])dr[24]; 
if (buffer != null) 
{ 
    groupBox1.Visible = true; 
    MemoryStream ms = new MemoryStream(buffer); 
    pictureBox1.Image = Image.FromStream(ms); 
}

How I can open Windows Photo Viewer with the image that display in the picture box...

rene
  • 41,474
  • 78
  • 114
  • 152
  • 1
    I think you'll find your answer here: http://stackoverflow.com/questions/6808029/open-image-in-windows-photo-viewer – DIF Apr 17 '14 at 09:16
  • It is good but i don not have the path of the image .the image is coming from the database. – Magdy Hussien Apr 17 '14 at 10:14

3 Answers3

0

You can open it with below Code:

Process.Start(@"C:\Picture.jpg");
Delta
  • 149
  • 9
0

You can save the image form the Picturebox to a temporary file and show that by running the PhotoViewer dll. That can be done with the rundll32 helper by using the Process class. Your code would look like this:

 // get a tempfilename and store the image
var tempFileName = Path.GetTempFileName();
pictureBox1.Image.Save(tempFileName, ImageFormat.Png);

string path = Environment.GetFolderPath(
    Environment.SpecialFolder.ProgramFiles);

// create our startup process and argument
var psi = new ProcessStartInfo(
    "rundll32.exe",
    String.Format( 
        "\"{0}{1}\", ImageView_Fullscreen {2}",
        Environment.Is64BitOperatingSystem?
            path.Replace(" (x86)",""):
            path
            ,
        @"\Windows Photo Viewer\PhotoViewer.dll",
        tempFileName)
    );

psi.UseShellExecute = false;

var viewer = Process.Start(psi);
// cleanup when done...
viewer.EnableRaisingEvents = true;
viewer.Exited += (o, args) =>
    {
        File.Delete(tempFileName);
    };

See this answer for how the Photoviewer can be started from the commandline.

Community
  • 1
  • 1
rene
  • 41,474
  • 78
  • 114
  • 152
-1

If you are working in a forum application you can add a picturebox with the toolbox, if u did that go to your properties of the picturebox and press the three dots next to the name image in your properties by doing that. Press local resource and you are in your own documents. hope this helped you

DlBreda
  • 77
  • 1
  • 1
  • 10