Click here to Skip to main content
16,018,534 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Below is my code:
C#
System.Drawing.Image bitmap = (System.Drawing.Image)Bitmap.FromFile(Server.MapPath(@"countimage\2.jpg")); // set image
      //draw the image object using a Graphics object
      Graphics graphicsImage = Graphics.FromImage(bitmap);

      //Set the alignment based on the coordinates
      StringFormat stringformat = new StringFormat();
      stringformat.Alignment = StringAlignment.Far;
      stringformat.LineAlignment = StringAlignment.Far;

      StringFormat stringformat2 = new StringFormat();
      stringformat2.Alignment = StringAlignment.Center;
      stringformat2.LineAlignment = StringAlignment.Center;

      //Set the font color/format/size etc..
      Color StringColor = System.Drawing.ColorTranslator.FromHtml("#fff");//customise color adding
      Color StringColor2 = System.Drawing.ColorTranslator.FromHtml("#fff");//customise color adding
      string Str_TextOnImage = Text2.Value;//Your Text On Image
      string Str_TextOnImage1 = Text3.Value;//Your Text On Image


      graphicsImage.DrawString(Str_TextOnImage, new Font("Lighthouse Personal Use", 50,
      FontStyle.Bold), new SolidBrush(StringColor), new Point(200, 250),
      stringformat);

      graphicsImage.DrawString(Str_TextOnImage1, new Font("Lighthouse Personal Use", 50,
    FontStyle.Bold), new SolidBrush(StringColor), new Point(380, 250),
    stringformat);


      bitmap.Save(Server.MapPath("out3/preview2.Jpg"));

Note: Code is running properly on my local host but once i am try to run this code to server it shows an error ,

Server Error in '/' Application.
A generic error occurred in GDI+.

C#
Line 45: 
Line 46: 
Line 47:         bitmap.Save(Server.MapPath("out1/preview3.Jpg"));
Line 48:     }
Line 49:     void img4()

please help to shot the issue,

Aditya Tyagi
Posted
Updated 14-Sep-15 23:35pm
v2

1 solution

Check your folders - and stop using relative paths. They have a tendency to fail because the page is moved (or copied) to a different folder on the webserver. Use an absolute path instead:
C#
Server.MapPath(@"~/Images/out1/preview3.Jpg")

If you look, you will find that the folder "out1" probably doesn't exist, or if it does, it doesn't have the required access permissions to let you app write to it.

But...once you "go live" you will have bigger problems: when you get two users trying to do the same thing at the same time, your fixed file names will cause problems because the file will be in use...
 
Share this answer
 

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