c# bitmap转成Emgu.CVmap对象
时间: 2023-10-25 18:13:07 浏览: 40
你可以使用Emgu.CV的`BitmapConverter`类将C#的`Bitmap`对象转换为`Emgu.CV.Mat`对象,如下所示:
```csharp
using Emgu.CV;
using Emgu.CV.Util;
using Emgu.CV.Structure;
using System.Drawing;
// Convert Bitmap to Mat
Bitmap bitmap = new Bitmap("image.bmp");
Mat mat = new Mat();
BitmapConverter.ToMat(bitmap, mat);
// Convert Mat to Bitmap
Bitmap bitmap2 = new Bitmap(mat.Bitmap);
```
这里我们使用了`BitmapConverter.ToMat()`方法将`Bitmap`对象转换为`Mat`对象,然后使用`Mat.Bitmap`属性将`Mat`对象转换回`Bitmap`对象。
相关问题
C# System.Drawing.Bitmap转BitmapImage
可以使用以下代码将C# System.Drawing.Bitmap转换为BitmapImage:
```csharp
using System.IO;
using System.Windows.Media.Imaging;
// 将 System.Drawing.Bitmap 转换为 BitmapImage
public static BitmapImage ConvertBitmapToBitmapImage(System.Drawing.Bitmap bitmap)
{
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Position = 0;
BitmapImage result = new BitmapImage();
result.BeginInit();
result.CacheOption = BitmapCacheOption.OnLoad;
result.StreamSource = stream;
result.EndInit();
return result;
}
}
```
使用方法:
```csharp
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap("path/to/image.jpg");
BitmapImage bitmapImage = ConvertBitmapToBitmapImage(bitmap);
```
emgucv image转bitmap
你可以使用EmguCV的`Bitmap`扩展方法将`Image<Bgr, Byte>`转换为`System.Drawing.Bitmap`,示例如下:
```csharp
using Emgu.CV;
using Emgu.CV.Structure;
// Load the image
Image<Bgr, Byte> image = new Image<Bgr, Byte>("path/to/image");
// Convert to Bitmap
System.Drawing.Bitmap bitmap = image.ToBitmap();
```
如果你想要将`Image<Gray, Byte>`转换为`System.Drawing.Bitmap`,可以使用以下代码:
```csharp
using Emgu.CV;
using Emgu.CV.Structure;
// Load the image
Image<Gray, Byte> image = new Image<Gray, Byte>("path/to/image");
// Convert to Bitmap
System.Drawing.Bitmap bitmap = image.Bitmap;
```