Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将本地图像转换为base64 javascript_Javascript_Android_Base64 - Fatal编程技术网

将本地图像转换为base64 javascript

将本地图像转换为base64 javascript,javascript,android,base64,Javascript,Android,Base64,作为。我知道如何使用它,但它的工作,若图像文件包括在项目中,而不是与其他文件夹。我正在android设备中测试,我的图像路径如下: /存储/extSdCard/1.jpg 如何将图像从本地移动设备转换为base64 function readImage(url, callback) { var request = new XMLHttpRequest(); request.onload = function() { var file = new FileR

作为。我知道如何使用它,但它的工作,若图像文件包括在项目中,而不是与其他文件夹。我正在android设备中测试,我的图像路径如下:

/存储/extSdCard/1.jpg

如何将图像从本地移动设备转换为base64

function readImage(url, callback) {   
    var request = new
    XMLHttpRequest();   request.onload = function() {
       var file = new FileReader();
       file.onloadend = function() {
          callback(file.result);
       }
       file.readAsDataURL(request.response);   };   
       request.open('GET', url);   
       request.responseType = 'blob';              
       request.send(); 
}
和调用函数

readImage('[path image] ',  function(base64) {  console.info(base64); 
});
和调用函数

readImage('[path image] ',  function(base64) {  console.info(base64); 
});