1

実行時に生成するビットマップイメージがあります。この方法で実行時に生成されて返されるため、ローカルURLはありません。この画像を実行時にcshtmlファイルまたはhtmlファイルに追加する方法はありますか?

public Bitmap GetBarcodeImage(string inputString)
    {

        Bitmap bitmap = new Bitmap(200,100);

        Graphics graphics = Graphics.FromImage(bitmap);

        graphics.Clear(Color.White);

        graphics.DrawString(inputString, new Font("Free 3 of 9",60,FontStyle.Regular), Brushes.Black, new PointF(0, 0));


        return bitmap;

    }
4

1 に答える 1

4

ビットマップを返すFileContentResultを返すasp.netmvcアクションを作成できます。このようなもの:

public FileContentResult imageGenerate(string s)
    {
        Bitmap b = getBarcodeImage(s);
        ... get byte array from bitmap ...
        return new FileContentResult(bytes, "image/bmp");
    }

次に、別のアクションのビューで、imageGenerateアクションを使用して画像を参照します

<img src="<%=Url.Action("imageGenerate","SomeController", new {s = "asdf"}) %>" />  
于 2012-05-17T20:03:01.620 に答える