How to save a Graphics object ...
-
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? -
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? -
Send FileStream, instead of Response.OutputStream to b.Save(...) method.
Intelligence is measured by common sense not by how many scholarly books you read.
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,
-
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?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 )