我可以解码图像文件中的QR码,如下所示 -
Bitmap bitmap = new Bitmap(imagePath);
BarcodeReader reader = new BarcodeReader();
Result result = reader.Decode(bitmap);
decodedData = result.Text;
但是我希望它能从Byte []中完成。
Byte[] imagefile;
using (var binaryReader = new BinaryReader(Request.Files["files"].InputStream))
{
imagefile = binaryReader.ReadBytes(Request.Files["files"].ContentLength);//image
}
我想从这个imagefile变量中读取QR码。有什么办法吗? 谢谢。
答案 0 :(得分:0)
怎么样:
using (var binaryReader = new BinaryReader(Request.Files["files"].InputStream))
{
byte[] imagefile = binaryReader.ReadBytes(Request.Files["files"].ContentLength); //image
using (MemoryStream memory = new MemoryStream(imagefile))
using (Image bitmap = Image.FromStream(memory)
{
BarcodeReader reader = new BarcodeReader();
Result result = reader.Decode(bitmap);
decodedData = result.Text;
}
}
或者可能更短:
using (Image bitmap = Image.FromStream(Request.Files["files"].InputStream))
{
BarcodeReader reader = new BarcodeReader();
Result result = reader.Decode(bitmap);
decodedData = result.Text;
}