0

我想让你知道从字节数组中获取图像的方法:

我正在使用这段代码,但它会抛出异常,如果大小超过 100 或数组的长度,如果它小于 50,它会保存一个混乱的图像

Bitmap b = new Bitmap(@"C:/difflena.jpg");

             byte[] pixels = lolo(b);
          MemoryStream stream = new MemoryStream(pixels, 0, pixels.Length);
          Bitmap bitmap = new Bitmap(stream);
          Image<Gray, byte> image = new Image<Gray, byte>(60, 60);
          image.Bytes = pixels;
          image.Save(file + "face" + "t" + ".bmp");
          if (image != null) { Label1.Text = "yes";


 public byte[] lolo(Bitmap n)
      {

          /*ImageFormat imageFormat = n.RawFormat;

          byte[] Ret=null;
          try
          {
              using (MemoryStream ms = new MemoryStream())
              {
                  n.Save(ms, imageFormat);
                  Ret = ms.ToArray();
              }

          }
          catch (Exception) { Label1.Text = "no"; }

          return Ret;}
4

0 回答 0