Answer the question
In order to leave comments, you need to log in
How to save a picture to Local Storage in Android?
On the desktop, I save the picture in Local Storage in Base64 (Fig. 1), then I pull it out and display it (Fig. 2) - everything is OK.
When I build this application in Phonegap, I see that the image type is not saved and the image, accordingly, is not displayed (the lost fragment is highlighted in Fig. 3).
If I manually add the missing fragment image/png;
, then the picture is displayed normally.
What Phonegap is doing with JS, what is happening is not clear, because. I don't see the project code.
Fig.1 Fig.2 Fig.3
Why is this happening and how to solve the problem?
Answer the question
In order to leave comments, you need to log in
Code
It seems that we managed to solve the problem, but with the help of a crutch :-)
index2.html:
$( document ).ready(function() {
$("#localText").text( localStorage.getItem("TextEntryName") );
var ls = localStorage.getItem("ImageEntryName");
var from = 5;
var to = 5000000;
$newls = ls.substring(from,to);
console.log("$newls = " + $newls);
$newnewls = "data:image/jpeg;" + $newls;
console.log("$newnewls = " + $newnewls);
$("#localImage").attr("src", $newnewls );
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question