Saving an image to the hard drive.
-
Hi. I have created and image in the Page_Load event: Bitmap bm = new Bitmap(300, 300); Graphics g = Graphics.FromImage(bm); g.FillRectangle(brush, 50,50,100,100); g.DrawLine(Pens.WhiteSmoke, 10, 10,180,10); g.DrawLine(Pens.White,10,10,10,180); After the line drawing code I added: bm.Save(Response.OutputStream, ImageFormat.Jpeg); bm.Save("C:\\mypic.gif", ImageFormat.Jpeg); bm.Dispose(); g.Dispose(); I would like to be able to save that image to my hard drive but I haven´t been able to do that, can anyone help me? This compiles just fine but when I want to view it in the browser and an error occurs. What am I doing wrong? Can someone please show me the error of my ways? Thanks, F
-
Hi. I have created and image in the Page_Load event: Bitmap bm = new Bitmap(300, 300); Graphics g = Graphics.FromImage(bm); g.FillRectangle(brush, 50,50,100,100); g.DrawLine(Pens.WhiteSmoke, 10, 10,180,10); g.DrawLine(Pens.White,10,10,10,180); After the line drawing code I added: bm.Save(Response.OutputStream, ImageFormat.Jpeg); bm.Save("C:\\mypic.gif", ImageFormat.Jpeg); bm.Dispose(); g.Dispose(); I would like to be able to save that image to my hard drive but I haven´t been able to do that, can anyone help me? This compiles just fine but when I want to view it in the browser and an error occurs. What am I doing wrong? Can someone please show me the error of my ways? Thanks, F
So what is the error you are getting? Are you certain the account running the ASP.NET worker process has permission to write to the C:\ directory?
-
Hi. I have created and image in the Page_Load event: Bitmap bm = new Bitmap(300, 300); Graphics g = Graphics.FromImage(bm); g.FillRectangle(brush, 50,50,100,100); g.DrawLine(Pens.WhiteSmoke, 10, 10,180,10); g.DrawLine(Pens.White,10,10,10,180); After the line drawing code I added: bm.Save(Response.OutputStream, ImageFormat.Jpeg); bm.Save("C:\\mypic.gif", ImageFormat.Jpeg); bm.Dispose(); g.Dispose(); I would like to be able to save that image to my hard drive but I haven´t been able to do that, can anyone help me? This compiles just fine but when I want to view it in the browser and an error occurs. What am I doing wrong? Can someone please show me the error of my ways? Thanks, F
Hello dear, I have just use this code of yours and it is working absolutely fine. Storing the picture in the given folder and displaying it in Browser or anything else.
Bitmap bm = new Bitmap(300, 300); Graphics g = Graphics.FromImage(bm); g.DrawLine(Pens.WhiteSmoke, 10, 10,180,10); g.DrawLine(Pens.White,10,10,10,180); bm.Save("C:\\mypic.gif", ImageFormat.Gif); bm.Dispose(); g.Dispose();
I have modified a little bit. regards Mubashir -
So what is the error you are getting? Are you certain the account running the ASP.NET worker process has permission to write to the C:\ directory?
Hi. I am just running this on my own PC and I pretty much copied the code from a book to learn and modify later. Everything seems to be OK but when I right-click and choose view in browser I get: A generic error occurred in GDI+ and this line gets the red color: bm.Save("C:\\Mypic.gif", ImageFormat.Jpeg); This just doesn´t make sense:confused: F
-
Hello dear, I have just use this code of yours and it is working absolutely fine. Storing the picture in the given folder and displaying it in Browser or anything else.
Bitmap bm = new Bitmap(300, 300); Graphics g = Graphics.FromImage(bm); g.DrawLine(Pens.WhiteSmoke, 10, 10,180,10); g.DrawLine(Pens.White,10,10,10,180); bm.Save("C:\\mypic.gif", ImageFormat.Gif); bm.Dispose(); g.Dispose();
I have modified a little bit. regards Mubashir -
Hi. I am just running this on my own PC and I pretty much copied the code from a book to learn and modify later. Everything seems to be OK but when I right-click and choose view in browser I get: A generic error occurred in GDI+ and this line gets the red color: bm.Save("C:\\Mypic.gif", ImageFormat.Jpeg); This just doesn´t make sense:confused: F
Perhaps you need to look at the
InnerException
of the exception you are getting? The outer exception may say "generic error", but often theInnerException
will have more details. I'm still betting that your ASP.NET worker process does not have permission to write to your C:\ directory. Any comment on that? -
Perhaps you need to look at the
InnerException
of the exception you are getting? The outer exception may say "generic error", but often theInnerException
will have more details. I'm still betting that your ASP.NET worker process does not have permission to write to your C:\ directory. Any comment on that? -
Perhaps you need to look at the
InnerException
of the exception you are getting? The outer exception may say "generic error", but often theInnerException
will have more details. I'm still betting that your ASP.NET worker process does not have permission to write to your C:\ directory. Any comment on that?Hi. It just so happens that I have 2 hard drives, c and e. I changed the code to: bm.Save("e:\\mypic.gif",ImageFormat.Jpeg); and it made all the difference in the world :), the image appears on drive e. You were absolutely right!! Very impressive. On the other hand I don´t understand why this small change makes such a big difference? Do you have any suggestions on how I can make the pic save to c? F
-
Read this carefully and thoroughly - Process and request identity in ASP.NET[^]