Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.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
C# 将img元素作为返回值传递_C#_Javascript_Windows Phone 8 - Fatal编程技术网

C# 将img元素作为返回值传递

C# 将img元素作为返回值传递,c#,javascript,windows-phone-8,C#,Javascript,Windows Phone 8,我正在开发html5 WP8应用程序。 在html/js端,我收集了一些数据(文本和图像),这些数据应该发送给c#,然后通过电子邮件转发。 我有javascript中的函数 function toEmail() { var dataToSend = getNextEntry(); return dataToSend; } 我从c#with称之为 这个很好用。但现在我应该对img.src中存储的图像执行同样的操作。我该怎么做?我应该转换返回值的数据类型等。可以将图像转换为base64字符串 例如

我正在开发html5 WP8应用程序。 在html/js端,我收集了一些数据(文本和图像),这些数据应该发送给c#,然后通过电子邮件转发。 我有javascript中的函数

function toEmail() {
var dataToSend = getNextEntry();
return dataToSend;
}
我从c#with称之为


这个很好用。但现在我应该对img.src中存储的图像执行同样的操作。我该怎么做?我应该转换返回值的数据类型等。

可以将图像转换为base64字符串

例如:

function img2base64(img)
{
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;

    var context = canvas.getContext("2d");
    context.drawImage(img, 0, 0, img.width, img.height);

    return canvas.toDataURL("image/jpeg"));
}
function img2base64(img)
{
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;

    var context = canvas.getContext("2d");
    context.drawImage(img, 0, 0, img.width, img.height);

    return canvas.toDataURL("image/jpeg"));
}