スキャンしたドキュメントの隅々(左上と右、左下と右)の画像を取得しようとしています。以下は私がそれを実装しようとした方法ですが、保存された画像を見ると、それらはすべて異なる部分ですが、左上隅のみであり、ドキュメント全体ではありません。これを変更する方法についての提案はありますか?
Bitmap result = fullImg;
//top-left
var bandImg1 = result.Clone(new System.Drawing.Rectangle(0, 0, 375, 375), fullImg.PixelFormat);
//top-right
var bandImg2 = result.Clone(new System.Drawing.Rectangle(100, 50, 375, 375), fullImg.PixelFormat);
//bottom-left
var bandImg3 = result.Clone(new System.Drawing.Rectangle(0, 50, 375, 375), fullImg.PixelFormat);
//bottom-right
var bandImg4 = result.Clone(new System.Drawing.Rectangle(100, 100, 375, 375), fullImg.PixelFormat);
bandImg1.Save("c:\\bandImg1.gif", System.Drawing.Imaging.ImageFormat.Gif);
bandImg2.Save("c:\\bandImg2.gif", System.Drawing.Imaging.ImageFormat.Gif);
bandImg3.Save("c:\\bandImg3.gif", System.Drawing.Imaging.ImageFormat.Gif);
bandImg4.Save("c:\\bandImg4.gif", System.Drawing.Imaging.ImageFormat.Gif);
-----以下の回答に基づいて追加されたコードを更新しました------
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);
bandImg1.Save("c:\\bandImg1.gif", System.Drawing.Imaging.ImageFormat.Gif);
bandImg2.Save("c:\\bandImg2.gif", System.Drawing.Imaging.ImageFormat.Gif);
bandImg3.Save("c:\\bandImg3.gif", System.Drawing.Imaging.ImageFormat.Gif);
bandImg4.Save("c:\\bandImg4.gif", System.Drawing.Imaging.ImageFormat.Gif);
string QRinfo = Process(bandImg1);
プロセス方法:
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;
}
}