扫描仪接口用的是: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中,然后存入数据库!!
[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中,然后存入数据库!!
解决方案 »
- c# SQL delete 语句使用问题,删除不了
- Exception Details: System.ArgumentException:
- 關於第三方控件的使用
- 求助:关于读取文本文件的问题
- DataGrid中,如何获取鼠标右键点击处的行号和列号?
- sql连接服务器问题(具有挑战性)(可以加分)欢迎(up)
- 如何让程序监听捕获摄像头按钮拍摄事件
- 如何在对话框中动态生成一个textBox?
- 命名空间System.Data.OracleClient在什么情况下才有效?
- 评评vc++ 的 .net厉害还是C#厉害?
- 使用c#如何得到系统性能(cpu 利用率,内存利用,应用程序等,也就是windows任务管理器中提到的)?
- 好奇怪!!??,为什么将asp.net的form提交给ASP时,如果表单中有中文的话就会变成乱码????
Image/Bitmap/Graphics对象或有DrawImage方法之类的,你自定义一个图象让它画就有了Bitmap bmp = new Bitmap(...);
Graphics g = Graphics.FromImage(bmp);//把这个 g 传给它画bmp.Save(MemoryStream ms,...);
byte[] bytes = ms.GetBuffer();
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 );
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
解决:...
PictureBox2.Image = Image.FromStream(iStream)
byte[] bytes = iStream.GetBuffer(); //二进制数据在这里
~
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事件是重画事件。救助于:做过图象采集的朋友
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)
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 。