//http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object/823966#823966


        public static async void SaveSmallBitmapAsJPG()
        {
            //  var path = new File(
            //                Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "OCR").AbsolutePath;
            //   var smallfilePath = System.IO.Path.Combine(path, "small.jpg");
            //   var bigfilePath = System.IO.Path.Combine(path, "OCR.jpg");

            BitmapFactory.Options opts = new BitmapFactory.Options();

            // load the image and have BitmapFactory resize it for us.
            opts.InSampleSize       = 4;     //  1/4 size
            opts.InJustDecodeBounds = false; //set to false to get the whole image not just the bounds
            Bitmap bitmap = await BitmapFactory.DecodeFileAsync(AppPath.bigfilePath(), opts);


            //rotate a bmp
            Matrix matrix = new Matrix();

            matrix.PostRotate(90);
            var rotatedBitmap = Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, true);


            //write it back
            using (var stream = new FileStream(AppPath.smallfilePath(), FileMode.Create))
            {
                await rotatedBitmap.CompressAsync(Bitmap.CompressFormat.Jpeg, 70, stream);//70% compressed

                stream.Close();
            }

            //    await stream.FlushAsync();
            // Free the native object associated with this bitmap, and clear the reference to the pixel data. This will not free the pixel data synchronously; it simply allows it to be garbage collected if there are no other references. The bitmap is marked as "dead", meaning it will throw an exception if getPixels() or setPixels() is called, and will draw nothing.
            //  bitmap.Recycle();
            //     GC.Collect();
        }
Exemple #2
0
        async Task <Bitmap> GetImage()
        {
            Bitmap bitmap = await BitmapFactory.DecodeFileAsync(AppPath.smallfilePath());

            // _imageView.SetImageBitmap(bitmap);
            WebViewForGif.Visibility = ViewStates.Gone;
            return(bitmap);
        }
Exemple #3
0
        private void CreateDirectoryForPictures()
        {
            AppPath.Dir = new File(AppPath.GetPath()); //get the directory path

            //if the folder doesn't exist then make it
            if (!AppPath.Dir.Exists())
            {
                AppPath.Dir.Mkdir();
            }
        }
        async Task <Bitmap> LoadImage()
        {
            //var path = new File(
            //    Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "OCR").AbsolutePath.ToString();
            //var filePath = System.IO.Path.Combine(path, "small.jpg");

            Bitmap bitmap = await BitmapFactory.DecodeFileAsync(AppPath.smallfilePath());

            // _imageView.SetImageBitmap(bitmap);
            return(bitmap);
        }
Exemple #5
0
        private async void UploadPic_Click(object sender, EventArgs e)
        {
            //if the app is there load it
            Bitmap bitmap = await GetImage();

            OCRmageView.SetImageBitmap(bitmap);

            BitmapOperations.SendImageForOCR(AppPath.smallfilePath());



            ResultText.Text = BitmapOperations.ResultTextFromOCR;
        }
        private async void loadImageClick(object sender, EventArgs e)
        {
            //if the app is there load it
            if (AppPath.smallfilePath().Contains("small.jpg"))
            {
                //async it
                Bitmap bitmap = await LoadImage();

                OCRimageView.SetImageBitmap(bitmap);
            }

            else
            {
                Toast.MakeText(this, "No image to show", ToastLength.Long);
            }
        }
Exemple #7
0
        private async void ReviewPic_Click(object sender, EventArgs e)
        {
            //just a test here
            LoadAnimatedGif();

            //if the app is there load it
            if (AppPath.smallfilePath().Contains("small.jpg"))
            {
                Bitmap bitmap = await LoadImage();

                OCRmageView.SetImageBitmap(bitmap);
            }
            else
            {
                Toast.MakeText(this, "No Image to show", ToastLength.Long);
            }
        }
Exemple #8
0
        //the result of the StartActivityForResult
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            // Make it available in the gallery by adding it to the media database

            Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);

            AppPath.OCRfile = new File(AppPath.bigfilePath());
            Uri contentUri = Uri.FromFile(AppPath.OCRfile);

            mediaScanIntent.SetData(contentUri);
            SendBroadcast(mediaScanIntent); //tell everything about the new pic?


            BitmapOperations.SaveSmallBitmapAsJPG();
        }
Exemple #9
0
        private void TakePic_Click(object sender, EventArgs e)
        {
            //weirdity going on, have to rebuild the path here instead of using the one already in the AppPath class
            var path = System.IO.Path.Combine(AppPath.GetPath(), "OCR.jpg");

            AppPath.OCRfile = new File(path); //return a file
            //if the path exists then run the camera
            if (AppPath.OCRfile.Exists())
            {
                //camera action
                Intent intent = new Intent(MediaStore.ActionImageCapture);

                //MediaStore – contents of the user’s device: audio (albums, artists, genres, playlists), images (including thumbnails) & video.
                intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(AppPath.OCRfile));

                StartActivityForResult(intent, 0);
            }

            else
            {
                Toast.MakeText(this, "No path working" + AppPath.OCRfile.ToString(), ToastLength.Long).Show();
            }
        }
Exemple #10
0
        async Task <Bitmap> LoadImage()
        {
            Bitmap bitmap = await BitmapFactory.DecodeFileAsync(AppPath.smallfilePath());

            return(bitmap);
        }