[DllImport("user32.DLL", ExactSpelling=true)]
internal static extern long SetForegroundWindow(IntPtr hWnd);
[DllImport("EZTW32.DLL", ExactSpelling=true)]
internal static extern long TWAIN_AcquireToClipboard(IntPtr handle,long t);
[DllImport("EZTW32.DLL", ExactSpelling=true)]
        internal static extern long TWAIN_SelectImageSource(IntPtr handle);
[DllImport("EZTW32.DLL", ExactSpelling=true)]
internal static extern long TWAIN_IsAvailable();
[DllImport("EZTW32.DLL", ExactSpelling=true)]
internal static extern long TWAIN_SetHideUI(long nHide);
try
{
if ( TWAIN_AcquireToClipboard(this.Handle,(long)4) == 0 )
{
SetForegroundWindow(this.Handle);
return;
} SetForegroundWindow(this.Handle);
Image img = (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
if ( img == null ) return;
this.picImage.SizeMode = PictureBoxSizeMode.StretchImage;
this.picImage.Image = img; this.CopyImage(); this.btnSave.Enabled = true;
}
catch ( Exception error )
{
MessageBox.Show(error.Message);
}

解决方案 »

  1.   

    private AxImgeditLibCtl.AxImgEdit axImgEdit;
    private AxScanLibCtl.AxImgScan axImgScan;private void buttonRead_Click(object sender, System.EventArgs e)
    {
    //侦测试扫描仪是否可用
    if(axImgScan.ScannerAvailable())
    {
    //打开扫描仪
    axImgScan.OpenScanner();
    axImgScan.Image=this.imagePath;//设定扫描仪扫描的图片存放路径
    axImgScan.StartScan();//开始扫描
    axImgEdit.Image=axImgScan.Image;//设定图片编辑器要编辑的图片路径
    axImgEdit.Display();//在编辑器中显示图片
    //设定图片局部选择框事件
    axImgEdit.SelectionRectDrawn +=  new AxImgeditLibCtl._DImgEditEvents_SelectionRectDrawnEventHandler(ImgEdit_SelectionRectDrawn);
    //设定图片局部选择框
    axImgEdit.DrawSelectionRect(0,0,125,160);
    }
    else
    {
    MessageBox.Show("数码相机未安装好!");
    return;
    }
    axImgScan.CloseScanner();

    }private void ImgEdit_SelectionRectDrawn(object sender, AxImgeditLibCtl._DImgEditEvents_SelectionRectDrawnEvent e)
    {
    //存在选定的图片区域
    if(axImgEdit.SelectionRectangle)
    {
    axImgEdit.Display();
    //将图片选定区域复制到剪切板
    axImgEdit.ClipboardCopy(e.left,e.top,e.width,e.height);
    //取得剪切板中的数据并赋给指定图片控件
    IDataObject data = Clipboard.GetDataObject();
    if (data.GetDataPresent(DataFormats.Bitmap))
    this.pictureBox.Image = (Image)data.GetData(DataFormats.Bitmap); }
    }