gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:11:54 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com