0

我在 C# 中找到了一个项目,我正在尝试将其转换为 vb.net,我几乎完成了它,但我无法让最后一个函数工作

Javascript 和 Ajax 代码

       $('#sendBtn').live('click', function () {
        var image = document.getElementById("signatureCanvas").toDataURL();
        document.getElementById("TextBox1").value = image;
        image = image.replace('data:image/png;base64,', '');

        $.ajax({
            type: 'POST',
            url: '/Default.aspx/UploadImage',
            data: '{ "imageData" : "' + image + '" }',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function (msg) {
                alert('Image sent!');
            }
        });
    });

VB.NET 代码

Namespace CanvasToServer
Partial Class _Default
    Inherits System.Web.UI.Page
    <WebMethod()>
    Public Shared Sub UploadImage(imageData As String)
        'FileStream fs = new FileStream("C:\\image.png", FileMode.Create);
        'FileStream fs = new FileStream(@"C:\inetpub\wwwroot\image.jpg", FileMode.Create);
        Dim fs As New FileStream("C:\inetpub\wwwroot\image.png", FileMode.Create)
        Dim bw As New BinaryWriter(fs)
        Dim data As Byte() = Convert.FromBase64String(imageData)
        bw.Write(data)
        bw.Close()
    End Sub
End Class
End Namespace

ASPX 代码

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="CanvasToServer._Default" %>

Tut 链接:http ://www.worldwidewhat.net/2011/06/send-canvas-content-to-server/

唯一不起作用的是保存到服务器功能,但我没有收到任何错误请指教

4

0 回答 0