系统网状物UI.WebControls.图像不包含保存的定义?正在保存图像



我有一个C#web应用程序,并且有一个由字节数组生成的映像。

byte[] imageBytes = Convert.FromBase64String(b64);
            MemoryStream ms = new MemoryStream(imageBytes, 0,
              imageBytes.Length);
            ImageStudent.ImageUrl = "data:image/jpeg;base64," + b64;

这样可以在web应用程序中完美地显示图像。但是,我想将此图像保存到项目中的文件夹中。我试过这个代码:

String FilePath;
            FilePath = Server.MapPath("~/Images/test2.jpg");
            ImageStudent.Save(FilePath, ImageFormat.Jpeg);

然而,我得到了错误:

System.Web.UI.WebControls.Image does not contain a definition for Save

我使用的所有.dll都需要用于Web应用程序上的其他功能,有其他方法可以保存此图像吗?

系统。绘画Image是您要查找的命名空间。

System.Drawing.Bitmap b = new System.Drawing.Bitmap(Server.MapPath("~/Images/test2.jpg"));
b.Save(saveFilePath , System.Drawing.Imaging.ImageFormat.Jpeg);

您只需要获取字节数组并将其保存在您想要的任何位置。一个基本的例子是:

File.WriteAllBytes(@"C:CopyofImage.jpg", imageByte);

除非您自己扩展,否则您无法为现有库(如Save on Image类)创建新方法。

最新更新