質問

Hey I am developing an app that could tag an image with the geolocation and the time stamp, using Phonegap. I have been able to tag the image by editing the image as a canvas. Now I need to save that edited image to the device Photo gallery/library as a new image or replace the image selected to be tagged. The purpose of using phonegap is that the application must function cross-platform. Is there any way this could be achieved ?

The following code edit the image as canvas and converts the image back to a Data URI.

var canvas = document.getElementById("canvasPnl");
        var context = canvas.getContext("2d");
        var imageObj = new Image();
        imageObj.onload = function(){

        context.drawImage(imageObj,0,0,300,300 );
        context.fillStyle="#FFFFFF";
        context.fillText('Latitude: '+ lat.toString()+' Longitude: '+ lon.toString(), 0, 10);
        context.fillText(new Date(), 0, 20);
        };
        imageObj.src=imageURI;
        dataURI= canvas.toDataURL();

Can this be converted to an image object and saved to phone gallery???

役に立ちましたか?

解決 2

I don't think you can make the image save in the gallery using just JavaScript but you can send the user to the image or display the image where the user can manually save it.

他のヒント

https://github.com/devgeeks/Canvas2ImagePlugin apparently does what you want, although I've not tried it.

Maybe you could try the plugin I wrote for IOS (If you want to save a canvas element to photogallery, you could get the dataURI of the canvas the use the downloadWithUrl method below). Hope it works for you.

here is the git link: https://github.com/Nomia/ImgDownloader

Short Example:

document.addEventListener("deviceready",onDeviceReady);

//google logo url
url = 'https://www.google.com/images/srpr/logo11w.png';

onDeviceReady = function(){
    cordova.plugins.imgDownloader.downloadWithUrl(url,function(){
        alert("success");
    },function(){
        alert("error");
    });        
}

//also you can try dataUri like: 1px gif
//url = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'

you can also save a local file to image gallery use the download method

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top