我创建了一个位图
,我想将它保存在我的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/