1

i want to write 3 text on the specific image. There isn't any problem on localhost. But on the server,i try everything but nothing has changed. always say: A generic error occurred in GDI+.

if i write text on the image step by step,i got same error. After i add first text, second and third text can not be added on the image because of proccessing on the image with first text.

Summary:

First i want to add text1 on img1 and Dispose. Second i want to add text2 on img1 and Dispose. Third i want to add text3 on img1 and Dispose.

  using (Bitmap bitmapMasterImage = new Bitmap(stringMasterImageName))
            {
                using (Graphics graphicsMasterImage = Graphics.FromImage(bitmapMasterImage))
                {
                    graphicsMasterImage.DrawString(stringText1, new Font("Arial", 20, FontStyle.Bold), new SolidBrush(colorStringColor), new Point(233, 134), stringformatWriteTextFormat);
                    graphicsMasterImage.DrawString(stringText2, new Font("Arial", 20, FontStyle.Bold), new SolidBrush(colorStringColor), new Point(233, 210), stringformatWriteTextFormat);
                    graphicsMasterImage.DrawString(stringText3, new Font("Arial", 20, FontStyle.Bold), new SolidBrush(colorStringColor), new Point(233, 300), stringformatWriteTextFormat);
                }

                Response.Clear();
                Response.ContentType = "image/jpeg";

                using (MemoryStream stream = new MemoryStream())
                {
                    bitmapMasterImage.Save(stream, ImageFormat.Jpeg);
                    bitmapMasterImage.Save(stringOutPutFileName);
                    stream.WriteTo(Response.OutputStream);
                }
            }

Thank You

tereško
  • 58,060
  • 25
  • 98
  • 150
  • 1
    Not sure if [this](http://stackoverflow.com/questions/336387/image-save-throws-a-gdi-exception-because-the-memory-stream-is-closed) helps, viz keep the stream open for the lifespan of your bitmap – StuartLC Oct 09 '12 at 13:25
  • What line does it fail on? When saving the file, right? – Michal Klouda Oct 09 '12 at 13:30
  • no fail on localhost.it runs correctly. Error on Server: A generic error occurred in GDI+. So i dont know the line fail on – Besim Erşahin Oct 09 '12 at 13:38

3 Answers3

0

This message usually appears when

  • you don't have write permissions to save the file
  • the path doesn't exists
  • the file is in use
Michal Klouda
  • 14,263
  • 7
  • 53
  • 77
  • the file is in use. i want to write 3 text on image.After adding first text on image,the image is in use. Thats why i can not add second text and third text. – Besim Erşahin Oct 09 '12 at 13:33
0

Check to make sure the paths setup the same way on the server (ie stringMasterImageName). Also, this could be a permission/security issue. Look here

danseery
  • 486
  • 2
  • 11
0

Try closing the brush streams

using (var brush = new SolidBrush(colorStringColor))
{
   ...         
}

Or use the built in brushes, these don't need to be closed.

graphicsMasterImage.DrawString(stringText1, font, Brushes.Black, new Point(233, 134), stringformatWriteTextFormat);
Harmon
  • 59
  • 2