扫描仪接口用的是:twain_32// ------ DSM entry point DAT_ variants:
[DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DSMparent( [In, Out] TwIdentity origin, IntPtr zeroptr, TwDG dg, TwDAT dat, TwMSG msg, ref IntPtr refptr ); [DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DSMident( [In, Out] TwIdentity origin, IntPtr zeroptr, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwIdentity idds ); [DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DSMstatus( [In, Out] TwIdentity origin, IntPtr zeroptr, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwStatus dsmstat );
// ------ DSM entry point DAT_ variants to DS:
[DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DSuserif( [In, Out] TwIdentity origin, [In, Out] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, TwUserInterface guif ); [DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DSevent( [In, Out] TwIdentity origin, [In, Out] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, ref TwEvent evt ); [DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DSstatus( [In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwStatus dsmstat ); [DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DScap( [In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwCapability capa ); [DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DSiinf( [In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwImageInfo imginf ); [DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DSixfer( [In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, ref IntPtr hbitmap ); [DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DSpxfer( [In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwPendingXfers pxfr );代码也是从:http://www.thecodeproject.com/dotnet/wiascriptingdotnet.asp 下载下来的!!要实现将扫描仪扫描出来的图像数据显示在PictureBox!根据下载的实例用:IntPtr指针对像,并且能在窗体上显示出扫描的图像数据,可这并不是想要的结果~~  要实现的是将图像数据显示在picturebox中,然后存入数据库!!

解决方案 »

  1.   

    楼主,都做到这步了,转换为二进制更是简单了,为什么不自己想想??"并且能在窗体上显示出扫描的图像数据" ----如果到了这步,代码里应该可以分离出
    Image/Bitmap/Graphics对象或有DrawImage方法之类的,你自定义一个图象让它画就有了Bitmap bmp = new Bitmap(...);
    Graphics g = Graphics.FromImage(bmp);//把这个 g 传给它画bmp.Save(MemoryStream ms,...);
    byte[] bytes = ms.GetBuffer();
      

  2.   

    可问题是扫描的图像数据是在:窗体:onPaint中画出来的代码:
                          realrect.Intersect(bmprect)
            If Not realrect.IsEmpty Then
                Dim bot As Integer = bmprect.Height - realrect.Bottom
                Dim hdc As IntPtr = e.Graphics.GetHdc()
                liblock.SetDIBitsTo(hdc, clprect.X, clprect.Y, realrect.Width, realrect.Height, realrect.X, bot, 0, bmprect.Height, pixptr, bmpptr, 0)
                e.Graphics.ReleaseHdc(hdc)SetDIBitsTo(这是个Api封装的):
             public void SetDIBitsTo(ref IntPtr hdc,int xdst,int ydst,int width,int height,int xsrc,int ysrc,int start,int lines,IntPtr bitsptr,IntPtr bmiptr,int color)
    {
    SetDIBitsToDevice( hdc, xdst, ydst, width, height,
    xsrc,ysrc, 0, lines, bitsptr, bmiptr, color );
    } [DllImport("gdi32.dll", ExactSpelling=true)]
    internal static extern int SetDIBitsToDevice( IntPtr hdc, int xdst, int ydst,
    int width, int height, int xsrc, int ysrc, int start, int lines,
    IntPtr bitsptr, IntPtr bmiptr, int color );
      

  3.   

    将扫描出来的图像数据重画到picturebox中现在能做到,可没办法读取picturebox中的image数据存入数据库~~~~~~~~~~~因为:picutrebox.image 是=nothing        Me.PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
            If Not Me.PictureBox1.Image Is Nothing Then
                Dim iStream As New MemoryStream
                PictureBox1.Image.Save(iStream, System.Drawing.Imaging.ImageFormat.Jpeg)
                'Dim a As Image
                PictureBox2.Image = Image.FromStream(iStream)
            End If  以上判断为nothing
      

  4.   

    C#代码,VB的你自己转---"可没办法读取picturebox中的image数据存入数据"
    解决:...
    PictureBox2.Image = Image.FromStream(iStream)
    byte[] bytes = iStream.GetBuffer(); //二进制数据在这里
      

  5.   

    楼上的,知道你的方法,可你有没有试过:在窗体上用Graphics 类画个图像,然后把这个图像取出来呢?有没有办法把:onpaint中重画后的图像取出来放到一个picturebox中。。
      

  6.   

    http://www.c-sharpcorner.com/Code/2003/March/FormPrinting.asp
      

  7.   

    有没有办法把:onpaint中重画后的图像取出来放到一个picturebox中。。 并存入数据库
      

  8.   

    将窗体中onpaint事件中的e.Graphics替换成this.pictureBox1.CreateGraphics不就行了
      

  9.   

    把pictureBox1.Image.Sava 不就可以保存了
      

  10.   

    楼上二位,我不知道你们有没有做过测试,如果在ONPaint事件画出的图像,再取:Picturebox1.image.save 保存?会出错。因为是picturebox1.image = null
    ~
      

  11.   

    方法一:
          public System.Drawint.Image createdImage = null;
          protected override void OnPaint(PaintEventArgs e)
    { ImageZoom(); }
          protected void ImageZoom()
    {
     Bitmap newBitmap = null;
      newBitmap = new Bitmap(800,600,PixelFormat.Format32bppArgb);
                    g = Graphics.FromImage(newBitmap);
                    createdImage = newBitmap;
                    this.Invalidate();
    };在重画后将图象放到createdImage对象中,这不是个解决办法,大家可以想想,ONPint事件是重画事件。救助于:做过图象采集的朋友
      

  12.   

    realrect.Intersect(bmprect)
       If Not realrect.IsEmpty Then
            Dim bot As Integer = bmprect.Height - realrect.Bottom
            Dim hdc As IntPtr = this.pictureBox1.CreateGraphics().GetHdc()
            liblock.SetDIBitsTo(hdc, clprect.X, clprect.Y, realrect.Width, realrect.Height, realrect.X, bot, 0, bmprect.Height, pixptr, bmpptr, 0)
            e.Graphics.ReleaseHdc(hdc)
      

  13.   

    TO :pupo(泡泡)Dim hdc As IntPtr = this.pictureBox1.CreateGraphics().GetHdc()加上这句话也只能把picturebox的指针给一个句柄对象,但还是不能解决将picturebox中的图片读取出来呀~~~~~If Not Me.PictureBox1.Image Is Nothing Then
                Dim iStream As New MemoryStream
                PictureBox1.Image.Save(iStream, System.Drawing.Imaging.ImageFormat.Jpeg)
                'Dim a As Image
                PictureBox2.Image = Image.FromStream(iStream)
            End If  
    因为Picutrebox.image =nothing 。