Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Saving an image to the hard drive.

Saving an image to the hard drive.

Scheduled Pinned Locked Moved ASP.NET
graphicshelpquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    naglbitur
    wrote on last edited by
    #1

    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

    M _ 2 Replies Last reply
    0
    • N naglbitur

      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

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      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?

      N 1 Reply Last reply
      0
      • N naglbitur

        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

        _ Offline
        _ Offline
        _mubashir
        wrote on last edited by
        #3

        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

        N 1 Reply Last reply
        0
        • M Mike Ellison

          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?

          N Offline
          N Offline
          naglbitur
          wrote on last edited by
          #4

          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

          M 1 Reply Last reply
          0
          • _ _mubashir

            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

            N Offline
            N Offline
            naglbitur
            wrote on last edited by
            #5

            Hi. If I comment out this line: bm.Save("C:\\mypic.gif", ImageFormat.Gif); I get no error reports but I want to save it to my hard drive. F

            1 Reply Last reply
            0
            • N naglbitur

              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

              M Offline
              M Offline
              Mike Ellison
              wrote on last edited by
              #6

              Perhaps you need to look at the InnerException of the exception you are getting? The outer exception may say "generic error", but often the InnerException 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?

              N 2 Replies Last reply
              0
              • M Mike Ellison

                Perhaps you need to look at the InnerException of the exception you are getting? The outer exception may say "generic error", but often the InnerException 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?

                N Offline
                N Offline
                naglbitur
                wrote on last edited by
                #7

                Hi. I am not really following you:( If you are right, how do we fix the problem? F

                M 1 Reply Last reply
                0
                • M Mike Ellison

                  Perhaps you need to look at the InnerException of the exception you are getting? The outer exception may say "generic error", but often the InnerException 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?

                  N Offline
                  N Offline
                  naglbitur
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • N naglbitur

                    Hi. I am not really following you:( If you are right, how do we fix the problem? F

                    M Offline
                    M Offline
                    Mike Ellison
                    wrote on last edited by
                    #9

                    Read this carefully and thoroughly - Process and request identity in ASP.NET[^]

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups