c# - 内存中的 System.Drawing.Image 需要 MD5 哈希

标签 c# .net image hash md5

内存中的 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/

相关文章:

c# - 无法添加对 'Microsoft Windows Installer Object Library' 的引用

c# - 在 C# 中找出我的 SQL Server 实例是否支持快照?

python - 如何使用 OpenCV 读取图像目录

CSS 同时旋转和替换图像

image - 使用 OpenCV 显示 float 组的问题

c# - 将列表拆分为列表列表,拆分元素

c# - EWS - 访问共享日历项目/约会

c# - 如何使用 C# 中的正则表达式将文本中的电子邮件地址替换为姓名?

c# - 如何为 asp.net webapi 构建可重用的 .Net 客户端,包括 IQueryable 功能等

c# - 显示矩阵,每个内部矩阵交替显示 0 和 1