内存中的 System.Drawing.Image 需要 MD5 哈希
最佳答案
这是一个基本片段。另请参阅@JaredReisinger 对某些问题的评论。
using System.Security.Cryptography;
using System.Text;
using System.Drawing.Imaging;
// ...
// get the bytes from the image
byte[] bytes = null;
using( MemoryStream ms = new MemoryStream() )
{
image.Save(ms,ImageFormat.Gif); // gif for example
bytes = ms.ToArray();
}
// hash the bytes
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] hash = md5.ComputeHash(bytes);
// make a hex string of the hash for display or whatever
StringBuilder sb = new StringBuilder();
foreach (byte b in hash)
{
sb.Append(b.ToString("x2").ToLower());
}
关于c# - 内存中的 System.Drawing.Image 需要 MD5 哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3410276/