My project run correctly but when publish it show generic error on this code, how to solve it.
protected void txtBrightness_TextChanged(object sender, EventArgs e)
{
string filename = Server.MapPath("Sample.jpg");
string toFilename = Server.MapPath("brightImage.jpg");
Bitmap bmp = new Bitmap(filename);
AdjustBrightness(bmp, Convert.ToInt16(txtBrightness.Text), toFilename);
bmp.Dispose();
Image1.ImageUrl = "~/brightImage.jpg";
}
public void AdjustBrightness(Bitmap Image, int Value, string toFileName)
{
System.Drawing.Bitmap TempBitmap = Image;
float FinalValue = (float)Value / 255.0f;
System.Drawing.Bitmap NewBitmap = new System.Drawing.Bitmap(TempBitmap.Width, TempBitmap.Height);
System.Drawing.Graphics NewGraphics = System.Drawing.Graphics.FromImage(NewBitmap);
float[][] FloatColorMatrix ={
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {FinalValue, FinalValue, FinalValue, 1, 1}
};
System.Drawing.Imaging.ColorMatrix NewColorMatrix = new System.Drawing.Imaging.ColorMatrix(FloatColorMatrix);
System.Drawing.Imaging.ImageAttributes Attributes = new System.Drawing.Imaging.ImageAttributes();
Attributes.SetColorMatrix(NewColorMatrix);
NewGraphics.DrawImage(TempBitmap, new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, System.Drawing.GraphicsUnit.Pixel, Attributes);
Attributes.Dispose();
NewGraphics.Dispose();
NewBitmap.Save(toFileName);
NewBitmap.Dispose();
}
Edit: Copied additional info from comments below
Exception is thrown at line: NewBitmap.Save(toFileName);
on debugging mode is run perfectly not showing error.