0

在一个 ASP.net (C#) Web 应用程序中,我使用 HTML 5 画布和 java 脚本创建了一个签名板。我们正在使用触摸设备(Android 和 iOS)捕获签名。

签名完成后,它将数据从画布发送到服务器,我将其转换为 .bmp 图像,并使用 Bitmap.Save(location, Format) 将其保存到服务器根程序目录上名为签名文件的目录中. 到目前为止,这已经为几个客户工作了好几个月。

不幸的是,我目前正在捕获异常但没有将它们发送到任何地方(我目前正在纠正的巨大错误)。如果必须,我将使用一些异常输出重新编译代码,以便我可以获得更多信息,但由于它是一个新客户端,我希望能够尽快修复这个问题,并且代码已经运行了很长时间没有问题,我很乐观,它是一个服务器设置。

IIS7 或 Windows Server 2008 中是否存在可能阻止应用程序将文件保存到服务器的安全设置。如果不是,则可能需要在服务器上安装某些东西以允许以下操作:

byte[] imageBytes = Convert.FromBase64String(suffix);

MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

ms.Write(imageBytes, 0, imageBytes.Length);

string thePath = Path.GetDirectoryName(saveLocation);

FileStream fs = new FileStream(thePath + @"\image.png", FileMode.Create);

BinaryWriter bw = new BinaryWriter(fs);

bw.Write(imageBytes);

bw.Close();

    if (string.IsNullOrEmpty(Path.GetFileName(saveLocation)))
        {

            string filename = Path.GetRandomFileName();
            filename = filename.Substring(0, filename.IndexOf('.'));
            filename = filename + Path.GetRandomFileName();
            filename = filename.Substring(0, filename.IndexOf('.'));

            theSaveLocation = saveLocation + @"\" + filename + "." + format;
        }


        ms = new MemoryStream();

        Bitmap input = (Bitmap)Bitmap.FromFile(thePath + @"\image.png");

        Bitmap result = ProcessBitmap(input, Color.White);

    result = (Bitmap)resizeImage((System.Drawing.Image)result, size);

    result.Save(theSaveLocation, System.Drawing.Imaging.ImageFormat.Bmp);

    input.Dispose();
        result.Dispose();
        ms.Close();

这是我上面使用的流程位图函数

private Bitmap ProcessBitmap(Bitmap bitmap, Color color)
{
    Bitmap temp = new Bitmap(bitmap.Width, bitmap.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    Graphics g = Graphics.FromImage(temp);
    g.Clear(color);
    g.DrawImage(bitmap, Point.Empty);
    return temp;
}

这是我在上面使用的 resizeImage 函数:

private static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
{

    int sourceWidth = imgToResize.Width;
    int sourceHeight = imgToResize.Height;

    float nPercent = 0;
    float nPercentW = 0;
    float nPercentH = 0;

    nPercentW = ((float)size.Width / (float)sourceWidth);
    nPercentH = ((float)size.Height / (float)sourceHeight);

    if (nPercentH < nPercentW)
        nPercent = nPercentH;
    else
        nPercent = nPercentW;

    int destWidth = (int)(sourceWidth * nPercent);
    int destHeight = (int)(sourceHeight * nPercent);


    Bitmap b = new Bitmap(destWidth, destHeight);
    Graphics g = Graphics.FromImage((System.Drawing.Image)b);


    g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
    g.Dispose();

    return (System.Drawing.Image)b;
}
4

0 回答 0