canvas.toDataURL does not result in image/jpeg data

10,546

Solution 1

  • Android 2.3 : I am unable to retrieve base64 data

canvas.toDataURL is not supported in old Android versions.

There's a js fix for that but performance might not be very good: https://code.google.com/p/todataurl-png-js/

Check here for more info: toDataURL not working on android browsers

  • Android 4.2 : I wrote this code c.toDataURL("image/jpeg"); but i got this data:image/png;base64

Android 4.x supports canvas.toDataURL; however, it doesn't support jpeg format (if you ask for a jpeg, it will return a png).

More details: https://github.com/scottjehl/Device-Bugs/issues/33

Solution 2

Only image/png is supported by old browsers (WebKits) and this is the only codec you can rely to be present. img/jpeg get added later on and is still not supported by many browsers.

For Android 2.3: try if you can do it in vanilla browser. If it works there then it is a PhoneGap issue and should be reported to the authors.

Share:
10,546

Related videos on Youtube

Milan V.
Author by

Milan V.

OVERVIEW A Developer by Heart, UX Reviewer, Team Lead and Tech Mentor CORE SKILLS iOS Swift Objective-C Fastlane TravisCI CircleCI tvOS watchOS webOS TizenTV Phonegap Ionic 1.0 JavaScript HTML5 Adobe Actionscript 3.0 Adobe Flash Adobe XD

Updated on September 16, 2022

Comments

  • Milan V.
    Milan V. over 1 year

    I am trying to save html5 canvas data to server using base64 + phonegap 2.5.

    platforms : windows phone 7 and 8 , Android and IOS.

    Basic need for image resizing is to optimize data before send over server.

    I am having issue with android platform base64 response method which are as follows

    Problems :

    1. Android 4.2 : I wrote this code c.toDataURL("image/jpeg"); but i got this data:image/png;base64
    2. Android 2.3 : I am unable to retrieve base64 data

    Am I doing anything wrong ?

  • Milan V.
    Milan V. almost 11 years
    Thanks a lot for your replay Luis. it helps me a lot.
  • Adam Marshall
    Adam Marshall over 9 years
    chrome on android 4.1+ seems to give "image/jpeg" if you ask for it