Skip to content

Cast image to base64 #15

@dzfweb

Description

@dzfweb

How do i cast the drawabled image into base64 string?

Activity

bradmartin

bradmartin commented on Feb 22, 2017

@bradmartin
Member

Use the image-source modules fromNativeSource(image) method passing in the image from the promise result to get an image-source. Then use toBase64String method on the image-source instance.

import * as imageSourceModule from 'image-source';

drawingPad.getDrawing().then((res) => {        
          console.log(res);
          let x = imageSourceModule.fromNativeSource(res);
          let the64string = x.toBase64String("PNG");
       });  

Let me know if that helps 😄

dzfweb

dzfweb commented on Feb 22, 2017

@dzfweb
Author

Thank you.
It works.
👍

steve-79

steve-79 commented on Sep 9, 2020

@steve-79

Just in case anyone is banging their head on the wall - the above code by bradmartin worked for me on android perfectly, however iOS in Nativescript Vue needed the x.toBase64String("PNG") to be lowercase as such: x.toBase64String('png')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bradmartin@dzfweb@steve-79

        Issue actions

          Cast image to base64 · Issue #15 · nativescript-community/nativescript-drawingpad