1

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 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

1 Answer 1

0

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.

1
  • Can you provide me the plugins you create?
    – Alston
    Mar 21, 2013 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.