将阈值图像转换为字节数组? [英] Converting a thresholded image into a byte array?

查看:167
本文介绍了将阈值图像转换为字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何将存储在'Bitmap'变量中的阈值图像转换为字节数组,并在C#中查看文本框或文本文件中的字节数组?

Can someone please tell me about how to convert a thresholded image stored in a 'Bitmap' variable into a byte array and view the byte array in a text box or a text file, in C#?

有人可以帮我提供代码吗?

Can someone please help me with the code to it?

我使用Aforge.net对图像进行了篡改 - 链接。并尝试在1s和0s中查看它的字节数组。

i have threshoded the image using Aforge.net - link. And trying to view the byte array of it in 1s and 0s.

谢谢。

推荐答案

如果你的图像是Bitmap,你可以使用

If your image is Bitmap you can use

LockBits 然后 Scan0 方法:

http://msdn.microsoft.com /query/dev11.query?appId=Dev11IDEF1&l=EN-US&k=k(System.Drawing.Imaging.BitmapData);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(DevLang-csharp) & rd = true

  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);
      }
    }

这篇关于将阈值图像转换为字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆