【发布时间】:2020-10-07 03:49:37
【问题描述】:
我正在尝试将图像加载到 asp 图像控件中。 该图像是从 zxing Barcode Writter 生成的。 我的问题是,我可以在不先物理保存的情况下加载它吗?
string barcode = "xxxxxx";
BarcodeWriter writer = new BarcodeWriter() { Format = BarcodeFormat.CODE_128 };
imgBarCode.ImageUrl = writer.Write(barcode);
...如何将 writer.Writer 引用到图像控件“imgBarCode”
【问题讨论】:
-
Write方法返回什么类型?如果您可以从BarcodeWriter实例中获取实际的图像字节,那么您可以Base64对其进行编码并从中构造一个数据URI。然后可以将其用作图像控件上的源/imageurl。参见(例如)this question -
@user1429080 它返回一个位图,正如您所说的将其保存在内存流中,转换为 base64 字符串并完成。编辑:谢谢队友