//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();
        }
Esempio n. 2
0
        async Task <Bitmap> GetImage()
        {
            Bitmap bitmap = await BitmapFactory.DecodeFileAsync(AppPath.smallfilePath());

            // _imageView.SetImageBitmap(bitmap);
            WebViewForGif.Visibility = ViewStates.Gone;
            return(bitmap);
        }
        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);
        }
Esempio n. 4
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);
            }
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        async Task <Bitmap> LoadImage()
        {
            Bitmap bitmap = await BitmapFactory.DecodeFileAsync(AppPath.smallfilePath());

            return(bitmap);
        }