2017-10-21 171 views

回答

0

使用C#.NET保存它您可以在浏览器客户端的图片。将图像数据发送到c#页面。

<input id="upload" name="upload" type="file" accept="image/*" /> 

它只是一个html文件输入,当选择或相机收到图像时,您可以获取QR图像数据。

$("#upload").on('change', function() { 
    var file = $(this)[0].files[0]; 
    if(!file) {//undefined 
     return; 
    } 
    if(!startLoading()) { 
     return; 
    } 
    var file = $(this)[0].files[0]; 
    var reader = new FileReader(); 
    reader.readAsDataURL(file); // read file as Data URL 
    reader.onload = function() { 
     var base64 = this.result; 
     //send this base64 string to c# backend page using ajax 
     ... 
}); 

然后代码在你的c#页面,得到base64字符串,改为图像。

byte[] arr2 = Convert.FromBase64String(base64); 
using (MemoryStream ms2 = new MemoryStream(arr2)) 
{ 
    System.Drawing.Bitmap bmp2 = new System.Drawing.Bitmap(ms2); 
    bmp2.Save(filePath + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 
    ...