I want to make image size smaller then its original size.I am using following code for compress the size images but it increased the image size from 1MB to 1.5MB
Any Other solution for compress large size images without change image original height,width.
public static byte[] CompressImage(Image img) {
int originalwidth = img.Width, originalheight = img.Height;
Bitmap bmpimage = new Bitmap(originalwidth, originalheight);
Graphics gf = Graphics.FromImage(bmpimage);
gf.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
gf.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.AssumeLinear;
gf.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
Rectangle rect = new Rectangle(0, 0, originalwidth, originalheight);
gf.DrawImage(img, rect, 0, 0, originalwidth, originalheight, GraphicsUnit.Pixel);
byte[] imagearray;
using (MemoryStream ms = new MemoryStream())
{
bmpimage.Save(ms, ImageFormat.Jpeg);
imagearray= ms.ToArray();
}
return imagearray;
}