Click here to Skip to main content
15,917,538 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Below this is my code, and how can i modified to save the image to the specific folder ?

What I have tried:

<pre> using (Bitmap graphicSurface = new Bitmap(panel1.Width, panel1.Height))
            {
                using (StreamWriter bitmapWriter = new StreamWriter("TEST.JPEG"))
                {
                    panel1.DrawToBitmap(graphicSurface, new Rectangle(0, 0, panel1.Width, panel1.Height));
                    graphicSurface.Save(bitmapWriter.BaseStream, ImageFormat.Jpeg);
                }
            }
        }
Posted
Updated 9-Aug-17 0:53am

1 solution

Change this:
C#
new StreamWriter("TEST.JPEG")

To this:
C#
new StreamWriter("[your desired path]\TEST.JPEG")

Notice that the parameter to pass is PATH, and not FILE...
StreamWriter Constructor (String) (System.IO)[^]
 
Share this answer
 
Comments
Richard Deeming 9-Aug-17 11:22am    
NB: It's C#, so you'll either need to escape the path separators:
new StreamWriter("C:\\Path\\To\\Save\\The\\File\\TEST.JPEG")

or use a verbatim string:
new StreamWriter(@"C:\Path\To\Save\The\File\TEST.JPEG")

String Literals | C# Language Reference[^]

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