私は現在、クラウド ストレージに移動されている従来の画像ライブラリ内に保存されている約 140,000 枚の画像のメタ データを格納するシステムを作成しています。以下を使用してjpgデータを取得しています...
System.Drawing.Image image = System.Drawing.Image.FromFile("filePath");
画像操作は初めてですが、幅、高さ、縦横比などの単純な値を取得するにはこれで問題ありませんが、バイト単位で表現されたjpgの物理ファイルサイズを取得する方法がわかりません。どんな助けでも大歓迎です。
ありがとう
後で比較するためのイメージの MD5 ハッシュを含む最終的なソリューション
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();
}