Attualmente sto scrivendo un sistema che memorizza metadati per circa 140.000 immagini ish memorizzate in una libreria di immagini legacy che vengono spostate nell'archivio cloud. Sto usando il seguente per ottenere i dati jpg ...Come ottenere la dimensione del file di "System.Drawing.Image"
System.Drawing.Image image = System.Drawing.Image.FromFile("filePath");
Im abbastanza nuovo per la manipolazione delle immagini, ma questo è bene per ottenere valori semplici come la larghezza, altezza, proporzioni, ecc, ma quello che non riesco a capire è come per recuperare la dimensione fisica del file del jpg espressa in byte. Qualsiasi aiuto sarebbe molto apprezzato.
Grazie
soluzione finale compreso un hash MD5 dell'immagine per dopo confrontarli
System.Drawing.Image image = System.Drawing.Image.FromFile(filePath);
if (image != null)
{
int width = image.Width;
int height = image.Height;
decimal aspectRatio = width > height ? decimal.divide(width, height) : decimal.divide(height, width);
int fileSize = (int)new System.IO.FileInfo(filePath).Length;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(fileSize))
{
image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
Byte[] imageBytes = stream.GetBuffer();
System.Security.Cryptography.MD5CryptoServiceProvider provider = new System.Security.Cryptography.MD5CryptoServiceProvider();
Byte[] hash = provider.ComputeHash(imageBytes);
System.Text.StringBuilder hashBuilder = new System.Text.StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
hashBuilder.Append(hash[i].ToString("X2"));
}
string md5 = hashBuilder.ToString();
}
image.Dispose();
}