Twain扫描输出将intptr转换为图像

时间:2014-04-08 13:08:47

标签: c# twain image-scanner

使用twain扫描仪和Mdi表格内的代码显示输出进行扫描我需要将其显示在图片框内,是否可以?我试着将intptr转换为image或somethnig,但没有找到正确的方法。

下面的代码;

                        case TwainCommand.TransferReady:
                        {
                        ArrayList pics = tw.TransferPictures();
                        EndingScan();
                        tw.CloseSrc();
                        picnumber++;
                        for (int i = 0; i < pics.Count; i++)
                        {
                          IntPtr img = (IntPtr)pics[i];
                          PicForm newpic = new PicForm(img);
                          newpic.MdiParent = this;
                          int picnum = i + 1;
                          newpic.Text = "ScanPass" + picnumber.ToString() + "_Pic" +                picnum.ToString();
                         newpic.Show();
                        }
                        break;

            public ArrayList TransferPictures()
                    {
                    ArrayList pics = new ArrayList();
                    if( srcds.Id == IntPtr.Zero )
                        return pics; 
                    TwRC rc;
                    IntPtr hbitmap = IntPtr.Zero;
                    TwPendingXfers pxfr = new TwPendingXfers();
                    do
                {
            pxfr.Count = 0;
            hbitmap = IntPtr.Zero;
            TwImageInfo iinf = new TwImageInfo();
            rc = DSiinf( appid, srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, iinf );
            if( rc != TwRC.Success )
                {
                CloseSrc();
                return pics;
                }
            rc = DSixfer( appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap );
            if( rc != TwRC.XferDone )
                {
                CloseSrc();
                return pics;
                }
            rc = DSpxfer( appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pxfr );
            if( rc != TwRC.Success )
                {
                CloseSrc();
                return pics;
                }
            pics.Add( hbitmap );
            }
        while( pxfr.Count != 0 );
        rc = DSpxfer( appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pxfr );
        return pics;
        }

1 个答案:

答案 0 :(得分:0)

您可以使用Bitmap构造函数。更多信息可在以下网址找到: http://msdn.microsoft.com/en-us/library/zy1a2d14.aspx