I want to reduce the picture size less than 50 kb.
Here i am giving the code which i have used in my application.
byte[] imageSize = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile uploadedImage = FileUpload1.PostedFile;
uploadedImage.InputStream.Read(imageSize(int)FileUpload1.PostedFile.ContentLength);
var fileLength1 = (FileUpload1.FileContent.Length.ToString());
byte[] ImageData = GenerateThumbnails(0.005, uploadedImage.InputStream);
private byte[] GenerateThumbnails(double scaleFactor, Stream sourcePath) {
var image = System.Drawing.Image.FromStream(sourcePath);
var newWidth = (int)(image.Width * scaleFactor);
var newHeight = (int)(image.Height * scaleFactor);
var thumbnailImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbnailImg);
thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imageRectangle);
MemoryStream ms = new MemoryStream();
image.Save(ms, ImageFormat.Jpeg);
return ms.ToArray();
}
Here the function GenerateThumbnails
reduces the actual size of the picture but it is very low. Suppose I upload the image which has a size of 800kb, the function will reduce only 40kb from 800kb. The size of the image affecting the performance of my website.