Files
KJD_WebService/AllBase/ImageErWeiMa.cs
T
2025-06-29 19:38:31 +08:00

57 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using ZXing;
namespace AllBase
{
public class ImageErWeiMa
{
/// <summary>
/// 是否二维码
/// </summary>
/// <param name="strSavePath"></param>
/// <returns></returns>
public bool GetErWeiMa(byte[] file, out int width, out int height, out Image initImage)
{
initImage = null;
width = 0;
height = 0;
try
{
MemoryStream ms = new MemoryStream(file);
initImage = Image.FromStream(ms);
ms.Close();
width = initImage.Width;
height = initImage.Height;
if (initImage.Width < 10 || initImage.Height < 10)
{
initImage = null;
return false;
}
BarcodeReader reader = new BarcodeReader();
Result result = reader.Decode((Bitmap)initImage);
if (result == null || string.IsNullOrEmpty(result.Text))
{
reader = null;
result = null;
//initImage = null;
return false;
}
reader = null;
result = null;
initImage = null;
}
catch
{
return false;
}
return true;
}
}
}