NeutrinosPlatform / cordova-plugin-document-scanner

cordova plugin for document scan
https://www.neutrinos.co/
MIT License
85 stars 60 forks source link

App crash on Android - trying to draw too large #47

Closed grimaldistudio closed 5 years ago

grimaldistudio commented 5 years ago

Hi, the plugin works fine but if you do not crop the image then the app crashes:

java.lang.RuntimeException: Canvas: trying to draw too large(122556768bytes) bitmap. at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260) at android.graphics.Canvas.drawBitmap(Canvas.java:1420) at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545) at android.widget.ImageView.onDraw(ImageView.java:1286) at android.view.View.draw(View.java:18318) ....

What can i do?

Tnx

ChrisTomAlx commented 5 years ago

Hey thanks for raising this issue with us. Could you send me your code and the image that is causing the problem ? Once I have these I will look into it and get back to you as soon as I can.

Cheers, Chris Neutrinos

grimaldistudio commented 5 years ago

Tnx for your reply, i am very happy.

environment: Cordova CLI: 7.1.0 Ionic CLI Version: 2.2.3 Ionic App Lib Version: 2.2.1 ios-deploy version: 2.0.0 ios-sim version: 5.0.13 OS: macOS Node Version: v7.2.1 Xcode version: Xcode 10.1 Build version 10B61

Code:


        document.addEventListener('deviceready', function () {
            scan.scanDoc(1, onSuccess, onFail);
        });
        function onSuccess(imageURI) {                       
            $scope.captured =  imageURI; 
        }

        function onFail(message) {
           if (window.cordova && $cordovaToast)
                $cordovaToast.showLongBottom('There was an unexpected error');      
        }

    }   

note: i select all the image area.

Cheers, Domenico IMG_20190308_165109

ChrisTomAlx commented 5 years ago

Couple of questions mostly because I am a newbie in ionic.

  1. $scope.captured = imageURI; in this line of code what exactly is $scope.captured.
  2. You are testing this on android right ?
  3. Could you give me your project or if that is not possible create a new project and recreate this issue then zip and sent it over for me to check out

Cheers, Chris Neutrinos

ChrisTomAlx commented 5 years ago

Whoops accidentally closed the issue!! My bad!!

grimaldistudio commented 5 years ago
  1. $scope.captured = imageURI; -> AngularJs to show image in view <img ng-src="captured" />, but if i replace with console.log(imageURI); app crash too.
  2. Yes Android.
  3. Sorry but i cannot give you my project, I'll try to make one in the next few days but I'm not sure.

Cheers, Domenico

ChrisTomAlx commented 5 years ago

I understand, this could be a device specific issue. The new project need not be too big, just the bare minimum so as to recreate the crash, if I can get my hands on such a project it will be a lot easier to help with the issue.

Cheers, Chris Neutrinos

grimaldistudio commented 5 years ago

Finally i did it! I made a 'spin off' of my project with only document scanner function but the core is the same. I hope it can be useful for tracing the problem.

Note:do you need the source code? ionic v1 + cordova?

Download apk here: http://tinyurl.com/y2ztzu88

ChrisTomAlx commented 5 years ago

@grimaldistudio Great!! I was starting to think you forgot all about this issue :D

Note:do you need the source code? ionic v1 + cordova?

Yes please !! That would be absolutely wonderful.

Cheers, Chris Neutrinos

grimaldistudio commented 5 years ago

Hi Chris, yeah...some time has passed :)

of course, download src code here: https://tinyurl.com/y4mkxs9u

If you need details, ask me. Tnx for your effort!

ChrisTomAlx commented 5 years ago

No worries :) It is my pleasure!! So I have some bad news; I am kinda stuck. The app shows a loading screen then it fades to white and then just remains white. I have enabled all the permissions as well. Any ideas what might be causing this?

Cheers, Chris Neutrinos

grimaldistudio commented 5 years ago

hi, i'm sorry there was an error, now corrected. Please download again.

ChrisTomAlx commented 5 years ago

Hey sorry about the delay. App would not let me login. Could you maybe put the code for the scanner before the login process on the login page just for my testing scenario?

Cheers, Chris Neutrinos

grimaldistudio commented 5 years ago

Hi Chris, I entered the precompiled login with username and password.

In any case I sent the new code without login. note: there is a "Scan Document" button.

Tnx Domenico

grimaldistudio commented 5 years ago

Hi Chris, did you see my last update?

Tnx Domenico

ChrisTomAlx commented 5 years ago

Hey @grimaldistudio

I totally dropped the ball on this, my bad. Will look into this as soon as I get some time off. Maybe tomorrow or day after. You referenced another issue here. As mentioned there, do you think being able to adjust quality of the plugin output will help? Those were the lines along which I was thinking. Anyhow I will get back to you with what I have sooner than later.

Cheers, Chris Neutrinos

ChrisTomAlx commented 5 years ago

Hey @grimaldistudio so I ran your app but I could not replicate this. What device did you test this on? Will try to get the same device on my side to test.

I think I have an idea on how to solve this (Get min and max res of OpenGL renderer and if the image is smaller than the min or larger than the max then scale the image up/down as necessary while keeping the aspect ratio). Will look into this and get back to you.

Cheers, Chris Neutrinos

grimaldistudio commented 5 years ago

I test on Samsung s6 -> remember to select the whole area. ->do you think being able to adjust quality of the plugin output will help? Yes, I think this is it

Thank you for your work, I hope you can solve it as soon as possible. Domenico

jpike88 commented 5 years ago

We're looking at using/contributing to this plugin, but I'm a little dismayed at how slow things are being improved, and am wondering whether we should roll our own instead.

Is this a side project, or a part of a commerical project you're working on?

ChrisTomAlx commented 5 years ago

Hey @jpike88

Quick Note :- Please do not hijack a thread. Start a new issue of your own and we can continue the discussion there if you would like to.

To answer your question this plugin is not part of any commercial project. We are busy with customer engagement and this has taken a back seat, hence the slow down in addition of enhancements. Active Dev will start by July. We would absolutely appreciate any contribution and will actively participate in helping contributors.

iOS Contribution

If you would like to contribute to the ios library please refer this comment and also our fork of the scanner library

Android Contribution

If you would like to contribute to the android library please refer our fork and also the original Just let me know if you need anything else, I will try and help to the best of my ability.

Cheers, Chris Neutrinos

ChrisTomAlx commented 5 years ago

Hey @ all. Finally got around to fixing the quality issue. From plugin version 4.1.0 onwards, you can now pass in quality property inside the options object. As shown here :- {quality : 1.0}.

As mentioned in the readme, 1.0 is the highest quality and 5.0 is the lowest quality. Any values not in this range will default to the highest quality of 1.0

Example :-

    scan.scanDoc(onSuccess, onFail, {sourceType : 1, fileName : "myfilename", quality : 2.5}); 
    // sourceType will by default take value 1 if no value is set | 0 for gallery | 1 for camera. 
    // fileName will take default value "image" if no value set. Supported only on 4.x.x plugin version

    function onSuccess(imageURI) {
        alert(imageURI);
        console.log(imageURI);
        //var image = document.getElementById('myImage');
        //image.src = imageURI; // For iOS, use image.src = imageURI + '?' + Date.now(); to solve issue 10 if unique fileName is not set.

    }

    function onFail(message) {
        alert('Failed because: ' + message);
    }

Closing this issue as upgrading to plugin version 4.1.0 should solve all of the following related issues #35, #46 & #47. If there are any problems in your trials please raise a new issue.

Cheers and thank you for being patient, Chris Neutrinos