Dear All,
I have created a function to resize an image and save it to the server. This is the code:-
try
{
System.Drawing.Image NewImg;
System.Drawing.Image.GetThumbnailImageAbort dummyCallBack =
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
NewImg = fullSizeImg.GetThumbnailImage(image_width, image_height, dummyCallBack, IntPtr.Zero);
NewImg.Save(path + image_name);
int x = image_width;
int y = image_height;
string image_path = path + "\\" + image_name;
Image oImg = Image.FromFile(image_path);
Bitmap bmp = new Bitmap(x,y);
System.Drawing.Imaging.Encoder Enc = System.Drawing.Imaging.Encoder.Transformation;
EncoderParameters EncParms = new EncoderParameters(1);
EncoderParameter EncParm;
Graphics gr = Graphics.FromImage(bmp);
gr.CompositingQuality = CompositingQuality.HighQuality;
gr.SmoothingMode = SmoothingMode.HighQuality;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.DrawImage(oImg, 0, 0, x, y);
gr.Save();
EncParms.Param = new EncoderParameter[]
{
new EncoderParameter(Enc,(long)EncoderValue.CompressionLZW),
new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L)
};
ImageCodecInfo ici ;
ici = GetProperEncoder(image_name);
bmp.Save(image_path, ici, EncParms);
oImg.Dispose();
bmp.Dispose();
}
catch (Exception e)
{
Console.WriteLine("Caught: {0}",e.Message);
}
However I am getting an exception on this line :-
bmp.Save(image_path, ici, EncParms);
The exception is
System.Object {System.ArgumentException} "Invalid Parameter Used"
Can anybody help me please?
Thanks for your help and time