【发布时间】:2013-06-27 17:54:30
【问题描述】:
谁能告诉我如何将存储在“位图”变量中的阈值图像转换为字节数组并在 C# 中的文本框或文本文件中查看字节数组?
有人可以帮我写代码吗?
我已使用 Aforge.net - link 对图像进行了阈值处理。并试图以 1 和 0 的形式查看它的字节数组。
谢谢。
【问题讨论】:
标签: c# image byte aforge threshold
谁能告诉我如何将存储在“位图”变量中的阈值图像转换为字节数组并在 C# 中的文本框或文本文件中查看字节数组?
有人可以帮我写代码吗?
我已使用 Aforge.net - link 对图像进行了阈值处理。并试图以 1 和 0 的形式查看它的字节数组。
谢谢。
【问题讨论】:
标签: c# image byte aforge threshold
如果您的图像是位图,您可以使用
LockBits 然后是 Scan0 方法:
public static Byte[] BmpToArray(Bitmap value) {
BitmapData data = value.LockBits(new Rectangle(0, 0, value.Width, value.Height), ImageLockMode.ReadOnly, value.PixelFormat);
try {
IntPtr ptr = data.Scan0;
int bytes = Math.Abs(data.Stride) * value.Height;
byte[] rgbValues = new byte[bytes];
Marshal.Copy(ptr, rgbValues, 0, bytes);
return rgbValues;
}
finally {
value.UnlockBits(data);
}
}
【讨论】: