示例#1
0
        public bool ReadFile(String fileName, Mat mat, CvEnum.ImreadModes loadType)
        {
            try
            {
                int rotation = 0;
                Android.Media.ExifInterface exif = new Android.Media.ExifInterface(fileName);
                int orientation = exif.GetAttributeInt(Android.Media.ExifInterface.TagOrientation, int.MinValue);
                switch (orientation)
                {
                case (int)Android.Media.Orientation.Rotate270:
                    rotation = 270;
                    break;

                case (int)Android.Media.Orientation.Rotate180:
                    rotation = 180;
                    break;

                case (int)Android.Media.Orientation.Rotate90:
                    rotation = 90;
                    break;
                }

                using (Android.Graphics.Bitmap bmp = Android.Graphics.BitmapFactory.DecodeFile(fileName))
                {
                    if (rotation == 0)
                    {
                        bmp.ToMat(mat);
                    }
                    else
                    {
                        Android.Graphics.Matrix matrix = new Android.Graphics.Matrix();
                        matrix.PostRotate(rotation);
                        using (Android.Graphics.Bitmap rotated = Android.Graphics.Bitmap.CreateBitmap(bmp, 0, 0, bmp.Width, bmp.Height, matrix, true))
                        {
                            //manually disposed sooner such that memory is released.
                            bmp.Dispose();
                            rotated.ToMat(mat);
                        }
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                //throw;
                return(false);
            }
        }
示例#2
0
 public bool ReadFile(String fileName, Mat mat, CvEnum.ImreadModes loadType)
 {
     try
     {
         using (CGDataProvider provider = new CGDataProvider(fileName))
             using (CGImage tmp = CGImage.FromPNG(provider, null, false, CGColorRenderingIntent.Default))
             {
                 CGImageExtension.ConvertCGImageToArray(tmp, mat, loadType);
             }
         return(true);
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         //throw;
         return(false);
     }
 }
示例#3
0
        /// <summary>
        /// Read the file into Mat using UIImage
        /// </summary>
        /// <param name="fileName">The image file to be read</param>
        /// <param name="mat">The Mat to read the file into</param>
        /// <param name="loadType">Image load type</param>
        /// <returns>True if successfully read the file into the Mat</returns>
        public bool ReadFile(String fileName, Mat mat, CvEnum.ImreadModes loadType)
        {
            try
            {
                //try again to load with UIImage
                using (UIImage tmp = UIImage.FromFile(fileName))
                {
                    tmp.CGImage.ToArray(mat, loadType);
                }

                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(false);
            }
        }
示例#4
0
 public static Mat LoadMat(string name, CvEnum.ImreadModes mode = ImreadModes.AnyColor)
 {
     //return new Mat(AssetsUtil.Assets, name);
     return(AssetsUtil.Assets.GetMat(name, mode));
 }