简体   繁体   中英

How to access the picture in SDCARD with phonegap on Android system

I have created a canvas (html5) element to let the user draw on it, after the drawing, they can save (a button) it: canvas.toDataURL("image/png"); will be executed and the encoded base64 dataURL string will be stored to a file. But I need to let the user view his paintings.


Here is the question: As the user save many story strings in a text file and the filesystem read the it, the memory will leak.
PhoneGap complains: java.lang.OutOfMemoryError , because the user saved too much dataURL strings. As all of them have to be reloaded to an array, error happens.

I suppose that if I save the user's drawing in image format(.jpg) instead of base64 dataURL, will it work?

  1. Will it solve the memory leak issue?
  2. How can I retrieve the images which are stored in the path like: sdcard/story/pics/ ?
    If I just want to access a recorded file, I can write:

    var record= new Media(src,onSuccess, onError); where the src could just be: story/rec/something.mp3 var record= new Media(src,onSuccess, onError); where the src could just be: story/rec/something.mp3 But the I can't access the image like this way.

  3. The solution should also work on iOS, because I have to deploy the app to iPad.
    Develop Environment :
    PhoneGap 1.8.0
    Android 4.0.3

I ran into a similar problem with binary files, and the bad news is that you cannot write binary data to the file system, as binary data cannot be transferred across the bridge into the native code.

I ended up writing a plugin to do the binary manipulation (or rather three plugins, one for iOS, another for Android and a third for BlackBerry).

I'm not sure what is causing you memory leak, but I would suggest only having one drawing in memory at once, unless you allow copy and paste between images, in which case I'd limit the app to two images in memory at once.

Whatever the leak is, it would have to be severe to use up all available memory, as most modern Android devices have quite a bit of memory on them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM