locked
A generic error occurred in GDI+ RRS feed

  • Question

  • User2077255217 posted

    Can someone help me to understand what' wrong with the following code? I'm trying to draw an image from two images and save the drawn image to Response.OutputStream but I'm always getting the un-clear "A generic error occurred in GDI+" pointing to MyImage.Save(Response.OutputStream, ImageFormat.Png);... thanks in advance.

    1    using System;
    2    using System.Drawing;
    3    using System.Drawing.Drawing2D;
    4    using System.Drawing.Imaging;
    5    //using System.Collections.Generic;
    6    //using System.Linq;
    7    //using System.Web;
    8    //using System.Web.UI;
    9    //using System.Web.UI.WebControls;
    10   
    11   public partial class ScoreImage : System.Web.UI.Page
    12   {
    13   	protected void Page_Load(object sender, EventArgs e)
    14   	{
    15   		Image BackgroundImage = Image.FromFile(Server.MapPath("~/background.png"));
    16   		PixelFormat BackgroundImagePixelFormat = BackgroundImage.PixelFormat;
    17   		if (BackgroundImagePixelFormat.ToString().Contains("Indexed"))
    18   		{
    19   			BackgroundImagePixelFormat = PixelFormat.Format24bppRgb;
    20   		}
    21   
    22   		Image ScanlinesImage = Image.FromFile(Server.MapPath("~/scanlines.png"));
    23   		PixelFormat ScanlinesImagePixelFormat = ScanlinesImage.PixelFormat;
    24   		if (ScanlinesImagePixelFormat.ToString().Contains("Indexed"))
    25   		{
    26   			ScanlinesImagePixelFormat = PixelFormat.Format24bppRgb;
    27   		}
    28   
    29   		using (Bitmap MyImage = new Bitmap(ScanlinesImage.Width, ScanlinesImage.Height, ScanlinesImagePixelFormat))
    30   		{
    31   			using (Graphics MyCanvas = Graphics.FromImage(MyImage))
    32   			{
    33   				using (ImageAttributes MyImageAttributes = new ImageAttributes())
    34   				{
    35   					ColorMatrix MyColorMatrix = new ColorMatrix();
    36   					MyColorMatrix.Matrix33 = 0.33F;
    37   					MyImageAttributes.SetColorMatrix(MyColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
    38   
    39   					MyCanvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
    40   					MyCanvas.PixelOffsetMode = PixelOffsetMode.HighQuality;
    41   					MyCanvas.SmoothingMode = SmoothingMode.AntiAlias;
    42   					MyCanvas.DrawImage(BackgroundImage, new Point(0, 0));
    43   					MyCanvas.DrawImage(
    44   						ScanlinesImage,
    45   						new Rectangle(0, 0, ScanlinesImage.Width, ScanlinesImage.Height),
    46   						0, 0, ScanlinesImage.Width, ScanlinesImage.Height,
    47   						GraphicsUnit.Pixel,
    48   						MyImageAttributes);
    49   
    50   					BackgroundImage.Dispose();
    51   					ScanlinesImage.Dispose();
    52   				}
    53   			}
    54   
    55   			//MyImage.Save(Server.MapPath("~/Result.png"), ScanlinesImage.RawFormat);
    56   			Response.ContentType = "image/png";
    57   			MyImage.Save(Response.OutputStream, ImageFormat.Png);
    58   		}
    59   	}
    60   }
    61   
    
     
    Saturday, December 6, 2008 2:29 AM

Answers

  • User2077255217 posted

    I found the answer here: http://aspalliance.com/319... I wouldn't imagine that such thing can be the problem!

    Only if the exception message was a bit clearer *sigh*

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 6, 2008 3:07 AM