3

を作成し、アップロードフォルダbitmapに保存したいと思います。これどうやってするの?

私のコード:

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\\";
4

2 に答える 2

3

Bitmapクラスには、Saveメソッドのいくつかのオーバーロードがあります。それらの1つは、パラメータとしてファイル名を取ります。これは、使用できることを意味します。

bitMapImage.Save(mynewpath + "somefilename.png", ImageFormat.Png);
于 2012-09-18T12:20:37.993 に答える
1

質問はコードと矛盾しているようです(画像からファイルをロードして返します)-とにかく:画像クラスには「保存」メソッドがあるので、同じServer.MapPathトリックでこれを使用してください。 ..ASP.NETアカウントにターゲットフォルダーへのアクセス/書き込み権限があることを確認してください。

string mynewpath = Request.PhysicalApplicationPath + "Upload\\myFile.png";
bitMapImage.Save(mynewpath);

備考:これはあなたのパスを使用していますが、これがあなたの問題にとって本当に正しい選択であるかどうかはわかりません-私が言ったように:MapPathは節約の賭けであるべきです。

于 2012-09-18T12:19:49.677 に答える