【问题标题】:Add bitmap image to cshtml mvc at runtime在运行时将位图图像添加到 cshtml mvc
【发布时间】:2012-05-25 10:14:32
【问题描述】:

我有一个将在运行时生成的位图图像。我没有它的本地 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;

    }

【问题讨论】:

    标签: asp.net asp.net-mvc bitmap barcode


    【解决方案1】:

    您可以创建一个 asp.net mvc 操作,该操作返回将返回位图的 FileContentResult。 像这样的:

    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"}) %>" />  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      相关资源
      最近更新 更多