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;
}
版权声明:本文为a254921185原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。