Exemplo n.º 1
0
      public Bitmap ToBitmap(Bitmap.Config config)
      {
         System.Drawing.Size size = Size;

         if (config == Bitmap.Config.Argb8888)
         {
            Bitmap result = Bitmap.CreateBitmap(size.Width, size.Height, Bitmap.Config.Argb8888);

            using (BitmapArgb8888Image bi = new BitmapArgb8888Image(result))
            using (Image<Rgba, Byte> tmp = ToImage<Rgba, Byte>())
            {
               tmp.Copy(bi, null);
            }
            return result;
         }
         else if (config == Bitmap.Config.Rgb565)
         {
            Bitmap result = Bitmap.CreateBitmap(size.Width, size.Height, Bitmap.Config.Rgb565);

            using (BitmapRgb565Image bi = new BitmapRgb565Image(result))
            using (Image<Bgr, Byte> tmp = ToImage<Bgr, Byte>())
               bi.ConvertFrom(tmp);
            return result;
         }
         else
         {
            throw new NotImplementedException("Only Bitmap config of Argb888 or Rgb565 is supported.");
         }
      }
Exemplo n.º 2
0
      /// <summary>
      /// Convert the Mat to Bitmap
      /// </summary>
      /// <param name="config">The bitmap config type. If null, Argb8888 will be used</param>
      /// <returns>The Bitmap</returns>
      public Bitmap ToBitmap(Bitmap.Config config = null)
      {
         System.Drawing.Size size = Size;

         if (config == null || config == Bitmap.Config.Argb8888)
         {
            Bitmap result = Bitmap.CreateBitmap(size.Width, size.Height, Bitmap.Config.Argb8888);
            int channels = NumberOfChannels;
            using (BitmapArgb8888Image bi = new BitmapArgb8888Image(result))
            {
               if (channels == 1)
               {
                  CvInvoke.CvtColor(this, bi.Mat, ColorConversion.Gray2Rgba);  
               } else if (channels == 3)
               {
                  CvInvoke.CvtColor(this, bi, ColorConversion.Bgr2Rgba);
               } else if (channels == 4)
               {
                  CvInvoke.CvtColor(this, bi, ColorConversion.Bgra2Rgba);
               }
               else
               {
                  using (Image<Rgba, Byte> tmp = ToImage<Rgba, Byte>())
                  {
                     tmp.Copy(bi, null);
                  }

               }
            }
            return result;
         }
         else if (config == Bitmap.Config.Rgb565)
         {
            Bitmap result = Bitmap.CreateBitmap(size.Width, size.Height, Bitmap.Config.Rgb565);

            using (BitmapRgb565Image bi = new BitmapRgb565Image(result))
            using (Image<Bgr, Byte> tmp = ToImage<Bgr, Byte>())
               bi.ConvertFrom(tmp);
            return result;
         }
         else
         {
            throw new NotImplementedException("Only Bitmap config of Argb888 or Rgb565 is supported.");
         }
      }