简体   繁体   中英

Convert jpeg image to hex format

我想将jpeg文件转换为十六进制格式,我发现了一些解决方案,其中最初将图像转换为字节数组,然后转换为十六进制格式。是否有任何方法可以在C#中直接将jpeg图像转换为十六进制格式。

using System.Runtime.Remoting.Metadata.W3cXsd2001 namespace :)

var str = new SoapHexBinary(File.ReadAllBytes(fName)).ToString();

or using BitConverter

var str2 = BitConverter.ToString(File.ReadAllBytes(fName));

There is no such function, but you can easily write one:

void ConvertToHex(string inputFilePath, string outputFilePath)
{
    var bytes = File.ReadAllBytes(inputFilePath);
    var hexString = string.Join("", bytes.Select(x => x.ToString("X2")));
    File.WriteAllText(outputFilePath, hexString);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM