Browse Source

Added function to convert Bitmap to IOutputArray.

pull/703/head
Canming Huang 4 years ago
parent
commit
d75098da48
  1. 14
      Emgu.CV.Platform/Android/MatAndroid.cs

14
Emgu.CV.Platform/Android/MatAndroid.cs

@ -54,13 +54,23 @@ namespace Emgu.CV
/// <param name="mat">The mat to copy Bitmap into</param> /// <param name="mat">The mat to copy Bitmap into</param>
/// <param name="bitmap">The bitmap to copy into mat</param> /// <param name="bitmap">The bitmap to copy into mat</param>
public static void ToMat(this Android.Graphics.Bitmap bitmap, Mat mat) public static void ToMat(this Android.Graphics.Bitmap bitmap, Mat mat)
{
ToArray(bitmap, mat);
}
/// <summary>
/// Convert a Bitmap to an image
/// </summary>
/// <param name="image">The image to copy Bitmap into</param>
/// <param name="bitmap">The bitmap to copy into image</param>
public static void ToArray(this Android.Graphics.Bitmap bitmap, IOutputArray image)
{ {
Android.Graphics.Bitmap.Config config = bitmap.GetConfig(); Android.Graphics.Bitmap.Config config = bitmap.GetConfig();
if (config.Equals(Android.Graphics.Bitmap.Config.Argb8888)) if (config.Equals(Android.Graphics.Bitmap.Config.Argb8888))
{ {
using (BitmapArgb8888Image bi = new BitmapArgb8888Image(bitmap)) using (BitmapArgb8888Image bi = new BitmapArgb8888Image(bitmap))
{ {
CvInvoke.CvtColor(bi, mat, ColorConversion.Rgba2Bgra);
CvInvoke.CvtColor(bi, image, ColorConversion.Rgba2Bgra);
} }
} }
else if (config.Equals(Android.Graphics.Bitmap.Config.Rgb565)) else if (config.Equals(Android.Graphics.Bitmap.Config.Rgb565))
@ -71,7 +81,7 @@ namespace Emgu.CV
GCHandle handle = GCHandle.Alloc(values, GCHandleType.Pinned); GCHandle handle = GCHandle.Alloc(values, GCHandleType.Pinned);
using (Mat bgra = new Mat(size, DepthType.Cv8U, 4, handle.AddrOfPinnedObject(), size.Width * 4)) using (Mat bgra = new Mat(size, DepthType.Cv8U, 4, handle.AddrOfPinnedObject(), size.Width * 4))
{ {
bgra.CopyTo(mat);
bgra.CopyTo(image);
} }
handle.Free(); handle.Free();
} }

Loading…
Cancel
Save