Thing I need to do is resize Image where ImageFormat is PNG.
Now I do this:
public static byte[] ResizeImage(Image image, int width, int height)
{
byte[] result = new byte[65000];
var destRect = new Rectangle(0, 0, width, height);
var destImage = new Bitmap(width, height);
destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
using (var graphics = Graphics.FromImage(destImage))
{
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
using (var wrapMode = new ImageAttributes())
{
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
}
}
using (MemoryStream stream = new MemoryStream())
{
destImage.Save(stream, ImageFormat.Png);
result = stream.ToArray();
return result;
}
}
The thing is at the "final stage" I need this image in byte array. This resizing method doesn't work well, because it makes this image "heavier".
Normally I use this method to convert image to PNG:
public byte[] imageToByteArray(Image imageIn) {
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
But the final "weight"(after imageTobyteArray) doesn't satisfy me, so I want to resize it to make it "lighter"(Resize method).
But in the final result my Resize method makes it like twice heavier, any ideas?
@for example after I take screenshot of my desktop(1366x768) and I use imageTobyteArray it takes 60 000 bytes, then I resize it(for example 1200x768) and it takes like 150 000 bytes in byteArray. Shouldn't be it less than 60 000 after resize? Correct me if my thinking is wrong