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. How to save a Graphics object ...

How to save a Graphics object ...

Scheduled Pinned Locked Moved ASP.NET
graphicsquestionhelpcsharpasp-net
4 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.
  • A Offline
    A Offline
    amin_behzadi
    wrote on last edited by
    #1

    Hi my dear friends. I want to write a text on an image and then save it to my server hard disk. then I could get help from this article but my question is how can I save the Graphics object into a image or bitmap and save it on my hard disk ? the code is : Bitmap b = new Bitmap(Server.MapPath("images/test.jpg")); Graphics gimg = Graphics.FromImage(b); gimg.SmoothingMode = SmoothingMode.AntiAlias; gimg.DrawString("my text", new Font("San Serif", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point100,100),StringFormat.GenericTypographic); gimg.DrawImage((System.Drawing.Image)b2, new Point(0, 0)); Response.ContentType = "image/jpeg"; b.Save(Response.OutputStream, ImageFormat.Jpeg); gimg.Dispose(); b.Dispose(); I dont want to write the new image in the browser . I just want to save it in a image file. How can I fix it?

    www.behzadi.net

    M C 2 Replies Last reply
    0
    • A amin_behzadi

      Hi my dear friends. I want to write a text on an image and then save it to my server hard disk. then I could get help from this article but my question is how can I save the Graphics object into a image or bitmap and save it on my hard disk ? the code is : Bitmap b = new Bitmap(Server.MapPath("images/test.jpg")); Graphics gimg = Graphics.FromImage(b); gimg.SmoothingMode = SmoothingMode.AntiAlias; gimg.DrawString("my text", new Font("San Serif", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point100,100),StringFormat.GenericTypographic); gimg.DrawImage((System.Drawing.Image)b2, new Point(0, 0)); Response.ContentType = "image/jpeg"; b.Save(Response.OutputStream, ImageFormat.Jpeg); gimg.Dispose(); b.Dispose(); I dont want to write the new image in the browser . I just want to save it in a image file. How can I fix it?

      www.behzadi.net

      M Offline
      M Offline
      M LN Rao
      wrote on last edited by
      #2

      Send FileStream, instead of Response.OutputStream to b.Save(...) method.

      Intelligence is measured by common sense not by how many scholarly books you read.

      A 1 Reply Last reply
      0
      • M M LN Rao

        Send FileStream, instead of Response.OutputStream to b.Save(...) method.

        Intelligence is measured by common sense not by how many scholarly books you read.

        A Offline
        A Offline
        amin_behzadi
        wrote on last edited by
        #3

        How can I do that , would you please explane more ? How can I save Graphics object with all changes in an image ? thx a lot for your help,

        www.behzadi.net

        1 Reply Last reply
        0
        • A amin_behzadi

          Hi my dear friends. I want to write a text on an image and then save it to my server hard disk. then I could get help from this article but my question is how can I save the Graphics object into a image or bitmap and save it on my hard disk ? the code is : Bitmap b = new Bitmap(Server.MapPath("images/test.jpg")); Graphics gimg = Graphics.FromImage(b); gimg.SmoothingMode = SmoothingMode.AntiAlias; gimg.DrawString("my text", new Font("San Serif", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point100,100),StringFormat.GenericTypographic); gimg.DrawImage((System.Drawing.Image)b2, new Point(0, 0)); Response.ContentType = "image/jpeg"; b.Save(Response.OutputStream, ImageFormat.Jpeg); gimg.Dispose(); b.Dispose(); I dont want to write the new image in the browser . I just want to save it in a image file. How can I fix it?

          www.behzadi.net

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          You cannot save a graphics object at all. You can save the Bitmap, which is what you're trying to do here anyhow. Your code looks like you're trying to send the file over the web, otherwise, why would you set the content type ? You need to create a file stream if you want to save it this way. Or, just give it a filename instead.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          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