Code Monkey home page Code Monkey logo

Comments (13)

bradmartin avatar bradmartin commented on May 27, 2024 1

I'm adding a method to do this in the source right now, will publish a minor with the new method also πŸ’― thanks for helping find the bug πŸ‘

from nativescript-drawingpad.

seankonig avatar seankonig commented on May 27, 2024 1

happy to help. your example works like a charm.

from nativescript-drawingpad.

megatdaharus avatar megatdaharus commented on May 27, 2024 1

thank you all for helping

from nativescript-drawingpad.

bradmartin avatar bradmartin commented on May 27, 2024

Can your print out the data and confirm what it is?

from nativescript-drawingpad.

seankonig avatar seankonig commented on May 27, 2024

Hi, yep this is crashing my app as well. Also running ns7, my app specifically crashes and closes after this line

image = ImageSource.fromResourceSync(data)

I have also tried:

const pad = this.DrawingPad.nativeElement;

        pad.getDrawing()
            .then(
                (data) => {
                    console.log(data);
                    ImageSource.fromData(data)
                        .then((res) => console.log(res))
                        .catch((error) => console.log(error));
                    // let image64 = image.toBase64String('png');
                },
                (err) => {
                    console.log(err);
                }
            )
            .catch((e) => console.log(e));

Just crashes
No output or errors though. In my case, the data value is android.graphics.Bitmap@4034c7f

Anything else I can try?
Thanks for the cool plugin

from nativescript-drawingpad.

bradmartin avatar bradmartin commented on May 27, 2024

This def worked at one time πŸ˜• because it was in the demo app and working fine to show the captured image into Image view in NS after the conversion from bitmap. Not sure what changed.

from nativescript-drawingpad.

seankonig avatar seankonig commented on May 27, 2024

Well, the ImageSource does not have a fromResourceSync() method. Could it have to do with how we get it?

from nativescript-drawingpad.

bradmartin avatar bradmartin commented on May 27, 2024

Yea... fromResource... was for app_Resource images - https://github.com/NativeScript/NativeScript/blob/b8d828bef93154db338939afd9ae4781097fd851/packages/core/image-source/index.android.ts#L96 you can see the source on android grabbing the resources here so in this instance we have the Bitmap already so fromDataSync() looks to be what you would use.

Try using https://github.com/NativeScript/NativeScript/blob/master/packages/core/image-source/index.android.ts#L152 fromDataSync()

from nativescript-drawingpad.

bradmartin avatar bradmartin commented on May 27, 2024

Ah... I see the issue now.

2021-01-13 09:55:48.547 4802-4802/org.nativescript.demo E/tivescript.dem: JNI ERROR (app bug): attempt to pass an instance of android.graphics.Bitmap as argument 1 to android.graphics.Bitmap android.graphics.BitmapFactory.decodeStream(java.io.InputStream)
2021-01-13 09:55:48.559 4802-4802/org.nativescript.demo A/tivescript.dem: java_vm_ext.cc:542] JNI DETECTED ERROR IN APPLICATION: bad arguments passed to android.graphics.Bitmap android.graphics.BitmapFactory.decodeStream(java.io.InputStream) (see above for details)
2021-01-13 09:55:48.559 4802-4802/org.nativescript.demo A/tivescript.dem: java_vm_ext.cc:542]     from java.lang.Object com.tns.Runtime.callJSMethodNative(int, int, java.lang.String, int, boolean, java.lang.Object[])
2021-01-13 09:55:48.559 4802-4802/org.nativescript.demo A/tivescript.dem: java_vm_ext.cc:542] "main" prio=5 tid=1 Runnable

That is the crash with fromData or fromDataSync we're passing the Bitmap and not a stream into the method so of course that crashes.

from nativescript-drawingpad.

bradmartin avatar bradmartin commented on May 27, 2024

@seankonig it's simply new ImageSource(data) to create the Image from a bitmap on android or UIImage on iOS.

    this._myDrawingPad.getDrawing().then(res => {      
      // convert native image data (bitmap on android) to imageSource for NS
      const image = new ImageSource(res);
      const base64imageString = image.toBase64String('jpg'); // if you need it as base64
      this.set('drawingImage', image);
    });

from nativescript-drawingpad.

seankonig avatar seankonig commented on May 27, 2024

Boom, thanks dude.

from nativescript-drawingpad.

bradmartin avatar bradmartin commented on May 27, 2024

getDrawingAsBase64(format?: "png" | "jpg" | "jpeg") - Promise (returns image as base64 string if successful)

this will be the method when 4.1.0 is published, just FYI. handles the conversion in the plugin directly since many people seem to need this :)

from nativescript-drawingpad.

seankonig avatar seankonig commented on May 27, 2024

That's really cool and makes a lot of sense to add. Thanks for including it. I Will update when you publish the new versionπŸ‘

from nativescript-drawingpad.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.