我看到位图 header 中有一个区域用于存储附加信息。那么,如果我要用 C# 编写图像,是否可以在 header 中添加额外的 ASCII 信息?
public void writeToPath(GMapControl form)
{
if(path == String.Empty || path == null)
path=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
int width = form.Size.Width;
int height = form.Size.Height;
Bitmap bm = new Bitmap(width, height);
form.DrawToBitmap(bm, new Rectangle(0, 0, width, height));
bm.Save("C:\SomePath\blah");
}
最佳答案
我相信在不深入研究 BITMAPINFOHEADER
的情况下解决这个问题的最简单方法是再次打开文件并编辑您要查找的特定字节。
这是一些(未经测试的)代码:
using (var stream = File.Open(@"C:\SomePath\blah.jpg", FileMode.Open))
{
var myBytes = new byte[] { /* put up to 4 bytes here */ };
stream.Position = 6; //there is some space at 0x006 and 0x0008 for your data
stream.Write(myBytes, 0, myBytes.Length);
}
关于c# - 如何在Bitmap header中存储ASCII信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15556322/