我正在嘗試使用 twaindotnet 掃描影像,只要用戶繼續掃描,我就想將掃描的影像添加到已經掃描的影像中。
換句話說,當用戶進行第一次掃描時,他會看到該掃描出現在 PictureBox 中,而當他執行第二次掃描時,他將在 PictureBox 中看到第一次掃描和第二次掃描。
在第三次掃描之后,他將在 PictureBox 中看到第一次掃描,第二次掃描下方和第三次掃描下方。
等等...
所以在 PictureBox 中實際上應該有一個大影像,它具有所有掃描的組合高度。
所以我嘗試了這個
private void buttonScan_Click(object sender, EventArgs e)
{
_twain = new Twain(new WinFormsWindowMessageHook(this));
_twain.ScanningComplete = _twain_ScanningComplete;
_twain.TransferImage = _twain_TransferImage;
_twain.SelectSource(_twain.SourceNames[0]);
ScanSettings scanSettings = new ScanSettings();
/// to do: figure out how to use scansettings
//scanSettings.Page.Size = TwainDotNet.TwainNative.PageType.A4;
//scanSettings.Resolution.Dpi = 800;
_twain.StartScanning(scanSettings);
}
private void _twain_ScanningComplete(object sender, ScanningCompleteEventArgs e)
{
buttonNextStep.Enabled = true;
_twain.ScanningComplete -= _twain_ScanningComplete;
_twain.TransferImage -= _twain_TransferImage;
}
private void _twain_TransferImage(object sender, TransferImageEventArgs e)
{
if (e.Image != null)
{
if (pictureBox1.Image == null)
{
pictureBox1.Image = e.Image;
}
else
{
Bitmap bitmap = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height e.Image.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawImage(pictureBox1.Image, 0, 0);
g.DrawImage(e.Image, 0, pictureBox1.Image.Height);
pictureBox1.Image = bitmap;
}
}
}
}
我基于這個
uj5u.com熱心網友回復:
嘗試強制影像.Width和.Height輸入g.DrawImage:
g.DrawImage(pictureBox1.Image, 0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height);
g.DrawImage(e.Image, 0, pictureBox1.Image.Height, e.Image.Width, e.Image.Height);
這是對此行為的解釋:https ://stackoverflow.com/a/47695040/2400834
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/493990.html
