检查位图以获得图像验证c#
我正在检查文档的四个角,以检查是否有图像。我怎样才能用下面的代码做到这一点。我得到文档的所有四个角,但我想得到哪个角有图像(二维码),然后将该角传递给后面的方法 代码:检查位图以获得图像验证c#,c#,winforms,bitmapimage,C#,Winforms,Bitmapimage,我正在检查文档的四个角,以检查是否有图像。我怎样才能用下面的代码做到这一点。我得到文档的所有四个角,但我想得到哪个角有图像(二维码),然后将该角传递给后面的方法 代码: using (var fullImg = new Bitmap(workGif)) { Bitmap result = fullImg; //top-left var band
using (var fullImg = new Bitmap(workGif))
{
Bitmap result = fullImg;
//top-left
var bandImg1 = result.Clone(new System.Drawing.Rectangle(0, 0, result.Width/2, result.Height/2), fullImg.PixelFormat);
//top-right
var bandImg2 = result.Clone(new System.Drawing.Rectangle(result.Width / 2, 0, result.Width / 2, result.Height / 2), fullImg.PixelFormat);
//bottom-left
var bandImg3 = result.Clone(new System.Drawing.Rectangle(0, result.Height / 2, result.Width / 2, result.Height / 2), fullImg.PixelFormat);
//bottom-right
var bandImg4 = result.Clone(new System.Drawing.Rectangle(result.Width / 2, result.Height / 2, result.Width / 2, result.Height / 2), fullImg.PixelFormat);
Bitmap[] corners = new Bitmap[] { bandImg1, bandImg2, bandImg3, bandImg4 };
string QRinfo = "";
for (int i = 0; i < corners.Length; ++i)
{
string tempQRinfo = Process(corners[i]);
if (tempQRinfo == null)
{
QRinfo = tempQRinfo;
switch (i)
{
case 0: break; //upper left
case 1: fullImg.RotateFlip(RotateFlipType.Rotate270FlipNone); break;
case 2: fullImg.RotateFlip(RotateFlipType.Rotate90FlipNone); break;
case 3: fullImg.RotateFlip(RotateFlipType.Rotate180FlipNone); break;
}
break;
}
}
你可能会被问到:这是一个包含图像处理组件的开源库-@Laurent很高兴知道并拥有它-谢谢。但我在寻找代码中的变通解决方案。正在检查我制作的克隆是否有图像。我想这里回答了这个问题:
public string Process(Bitmap bitmap)
{
var reader = new com.google.zxing.qrcode.QRCodeReader();
try
{
LuminanceSource source = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);
var binarizer = new HybridBinarizer(source);
var binBitmap = new BinaryBitmap(binarizer);
return reader.decode(binBitmap).Text;
}
catch (Exception e)
{
return e.Message;
}
}