c# - 如何使用文件流保存位图

标签 c# asp.net-mvc asp.net-mvc-3 c#-4.0

我创建了一个位图,我想将它保存在我的upload 文件夹中。我怎样才能做到这一点?

我的代码:

public FileResult image(string image)
{
    var bitMapImage = new Bitmap(Server.MapPath("/Content/themes/base/images/photo.png"));
    Graphics graphicImage = Graphics.FromImage(bitMapImage);
    graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
    graphicImage.DrawString(image, new Font("Trebuchet MS,Trebuchet,Arial,sans-serif", 10, FontStyle.Bold), SystemBrushes.WindowFrame, new Point(15, 5));
    graphicImage.DrawArc(new Pen(Color.Red, 3), 90, 235, 150, 50, 0, 360);
    MemoryStream str = new MemoryStream();
    bitMapImage.Save(str, ImageFormat.Png);
    return File(str.ToArray(), "image/png");
}

我将使用的路径:

string mynewpath = Request.PhysicalApplicationPath + "Upload\\";

最佳答案

Bitmap 类有几个重载 Save方法。其中之一将文件名作为参数,这意味着您可以使用

bitMapImage.Save(mynewpath + "somefilename.png", ImageFormat.Png);

关于c# - 如何使用文件流保存位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12476663/

相关文章:

c# - 在 .NET Core 2.x csproj 项目中可靠地生成 C# 代码?

c# - 如何在 C# 中将 XML 转换为对象格式

jquery - ASP.NET MVC jQuery 发布错误

c# - 放置 Database.SetInitializer 的地方

asp.net-mvc - 没有为此对象定义无参数构造函数?

c# - 为什么 DateTime.ParseExact 不适用于美国以外的这个示例?

c# - 获取所有具有特定 fieldName 的 lucene 值

c# - 数据验证 - 哪个更快?

c# - ASP.NET Identity - HttpContext 没有 GetOwinContext 的扩展方法

c# - 禁用 Newtonsoft 更改 JSON 大小写