如何阅读TIFF头文件c#? [英] How to read TIFF header File c#?
本文介绍了如何阅读TIFF头文件c#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何以二进制格式读取文件。例如,一个tiff图像文件可能具有以下十进制格式0000 4949 002A 0000.
如何在c#中获取这些值?
解决方案
以下是我如何通常以十六进制格式读取文件,根据需要更改标题:
using System;
使用System.Linq;
使用System.IO;
命名空间FileToHex
{
class程序
{
static void Main(string [] args)
{
//从文件只读4个字节
const int HEADER_SIZE = 4;
byte [] bytesFile = new byte [HEADER_SIZE];
使用(FileStream fs = File.OpenRead(@C:\temp\FileToHex\ex.tiff))
{
fs.Read(bytesFile, 0,HEADER_SIZE);
fs.Close();
}
string hex = BitConverter.ToString(bytesFile);
string [] header = hex.Split(new Char [] {' - '})。ToArray();
Console.WriteLine(System.String.Join(,header));
Console.ReadLine();
code $ pre
I wanna know how it is possible to read a file in binary format.
for example a tiff image file may have the following binary format in hex 0000 4949 002A 0000.
how can i get these values in c#?
解决方案 Here is how I usually read files in hexadecimal format, changed for the header, as you need:
using System;
using System.Linq;
using System.IO;
namespace FileToHex
{
class Program
{
static void Main(string[] args)
{
//read only 4 bytes from the file
const int HEADER_SIZE = 4;
byte[] bytesFile = new byte[HEADER_SIZE];
using (FileStream fs = File.OpenRead(@"C:\temp\FileToHex\ex.tiff"))
{
fs.Read(bytesFile, 0, HEADER_SIZE);
fs.Close();
}
string hex = BitConverter.ToString(bytesFile);
string[] header = hex.Split(new Char[] { '-' }).ToArray();
Console.WriteLine(System.String.Join("", header));
Console.ReadLine();
}
}
}
这篇关于如何阅读TIFF头文件c#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文