将base64string转换为图像



我正在将base64string从android应用程序发送到webservice。webservice再次将base64string转换为image。但当我再次将base64string转换为图像时,我从web服务中得到了以下错误:

"GDI+中发生一般错误。"此错误正在服务器上获取只有

下面是我的代码:

public string Base64ToImage(string base64String, string imgName)
{
    try
    {
        // Convert Base64 String to byte[]
        byte[] imageBytes = Convert.FromBase64String(base64String);
        MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
        // Convert byte[] to Image
        ms.Write(imageBytes, 0, imageBytes.Length);
        System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
        image.Save(
            "D:\apps\PJP_TEST\PJPTest\Online\ImageStorage\" + imgName);
        return "Success";
    }
    catch (Exception ex)
    {
        return ex.Message;
    }           
}

我猜"服务器"的意思是"web服务器"。您可能没有在文件夹D:appsPJP_TESTPJPTestOnlineImageStorage中写入的权限。

检查运行应用程序的用户是否具有对指定文件夹的读写访问权限。

如前所述,直接写入文件更容易:

File.WriteAllBytes( Path.Combine
                    ( @"D:appsPJP_TESTPJPTestOnlineImageStorage"
                    , imgName
                    )
                  , imageBytes
                  );

最新更新