C# bitmap 位图转为mat类型
直接贴代码
/// <summary>
/// bitmap 位图转为mat类型
/// </summary>
/// <param name="bitmap"></param>
/// <returns></returns>
public static Mat Bitmap2Mat(Bitmap bitmap)
{
MemoryStream s2_ms = null;
Mat source = null;
try
{
using (s2_ms = new MemoryStream())
{
bitmap.Save(s2_ms, System.Drawing.Imaging.ImageFormat.Bmp);
source = Mat.FromStream(s2_ms, ImreadModes.AnyColor);
}
}
catch (Exception e)
{
}
finally
{
if (s2_ms != null)
{
s2_ms.Close();
s2_ms = null;
}
GC.Collect();
}
return source;
}