加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 04:26:22 所属栏目:百科 来源:网络整理
导读:在内存System.Drawing. Image中需要MD5哈希 解决方法 这是一个基本的片段.有关一些问题,另请参阅@JaredReisinger的评论. using System.Security.Cryptography;using System.Text;using System.Drawing.Imaging;// ...// get the bytes from the imagebyte[]
在内存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());
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读