Reputation: 5126
I want to convert a jpeg file to hexadecimal format, I found some of the solutions where initially the image is converted into byte array and then to hex format.Is there any method which directly convert jpeg image to hex format in C#.
Upvotes: 1
Views: 20252
Reputation: 35373
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));
Upvotes: 8
Reputation: 14571
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);
}
Upvotes: 1