I'm having an image variable which contains a .png picture.
In order to calculate how big it would be on disk I'm currently asving it to a memory cache and then using the length of that "memory file" to calculate if it is within the file sizes I want.
As that seems pretty inefficient to me (a "real" calculation is probably faster and less memory intense) I'm wondering if there is a way to do it in a different way.
Example:
private bool IsImageTooLarge(Image img, long maxSize)
{
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
if (ms.ToArray().Length > maxSize)
{
return true;
}
}
return false;
}
Additional infos: The source code is part of what will be a .dll thus web specific things won't work there as I need to do things with C# itself.