I have a screen shot I take in my mobile app. The screen shot takes about 32 KB when saved as a png on a disk.
I am sending these to a central SQL Server and 32 KB is too big for that amount of times I will need to store that screen shot (approx 2500 times a day).
Is there any kind of trickery that I can do to get it to save smaller?
Here is the code I am using now to take it from Bitmap
to bytes (to send to the server for storage):
MemoryStream stream = new MemoryStream();
_signatureImage.Save(stream, ImageFormat.Png);
return stream.ToArray();
_signatureImage
is a Bitmap
and is the screenshot in question.
Here is an example of the screen shot I am saving:
Things that pop to mind (but I don't know how to do them):
Note, this all has to be done programatically, and cannot take very long, so complex image manipulations are out.
Thanks for any help.
private static Image ResizeImage(int newSize, Image originalImage)
{
if (originalImage.Width <= newSize)
newSize = originalImage.Width;
var newHeight = originalImage.Height * newSize / originalImage.Width;
if (newHeight > newSize)
{
// Resize with height instead
newSize = originalImage.Width * newSize / originalImage.Height;
newHeight = newSize;
}
return originalImage.GetThumbnailImage(newSize, newHeight, null, IntPtr.Zero);
}
This should work with your Bitmap object Type and resize the Height or Width, depending on which is appropriate for your image dimensions. It will also maintain scale.
EDIT:
You could create a new Bitmap object and resize your original image into that Bitmap object.
Bitmap b = new Bitmap(newWidth, newHeight);
Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(imgToResize, 0, 0, newWidth, newHeight);
g.Dispose();
return (Image)b;
I don't have the Compact Framework installed, but it seems that this should work for you.