/// <summary> /// Convert Image object to Bitmap /// </summary> /// <param name="config">The Bitmap Config</param> /// <returns>The Bitmap</returns> public static Android.Graphics.Bitmap ToBitmap <TColor, TDepth>(this Image <TColor, TDepth> image, Android.Graphics.Bitmap.Config config) where TColor : struct, IColor where TDepth : new() { System.Drawing.Size size = image.Size; if (config == Android.Graphics.Bitmap.Config.Argb8888) { Android.Graphics.Bitmap result = Android.Graphics.Bitmap.CreateBitmap(size.Width, size.Height, Android.Graphics.Bitmap.Config.Argb8888); using (BitmapArgb8888Image bi = new BitmapArgb8888Image(result)) { bi.ConvertFrom(image); //CvInvoke.cvSet(bi, new MCvScalar(0, 0, 255, 255), IntPtr.Zero); } return(result); } else if (config == Android.Graphics.Bitmap.Config.Rgb565) { Android.Graphics.Bitmap result = Android.Graphics.Bitmap.CreateBitmap(size.Width, size.Height, Android.Graphics.Bitmap.Config.Rgb565); using (BitmapRgb565Image bi = new BitmapRgb565Image(result)) bi.ConvertFrom(image); return(result); } else { throw new NotImplementedException("Only Bitmap config of Argb888 or Rgb565 is supported."); } }
/// <summary> /// Read image file from Assets /// </summary> /// <param name="assets">The Asset manager</param> /// <param name="fileName">The name of the file</param> public static Image <TColor, TDepth> GetImage <TColor, TDepth>(this AssetManager assets, String fileName) where TColor : struct, IColor where TDepth : new() { using (Stream imageStream = assets.Open(fileName)) using (Android.Graphics.Bitmap imageBmp = BitmapFactory.DecodeStream(imageStream)) return(imageBmp.ToImage <TColor, TDepth>()); }