医药CRM系统开发

自已做医药CRM系统有四年了,终于可以算个产品了,努力市场化,今年重种将医药营销的理念加入CRM

导航

拍照

Posted on 2013-07-07 15:06  hhq80  阅读(258)  评论(0编辑  收藏  举报

Imports System
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.Drawing.Imaging
Class Camera
    Private Const WM_CAP_START = WM_USER
    Private Const WM_CAP_STOP = WM_CAP_START + 68
    Private Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
    Private Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
    Private Const WM_CAP_SAVEDIB = WM_CAP_START + 25
    Private Const WM_CAP_GRAB_FRAME = WM_CAP_START + 60
    Private Const WM_CAP_SEQUENCE = WM_CAP_START + 62
    Private Const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20
    Private Const WM_CAP_SEQUENCE_NOFILE = WM_CAP_START + 63
    Private Const WM_CAP_SET_OVERLAY = WM_CAP_START + 51
    Private Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
    Private Const WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START + 6
    Private Const WM_CAP_SET_CALLBACK_ERROR = WM_CAP_START + 2
    Private Const WM_CAP_SET_CALLBACK_STATUSA = WM_CAP_START + 3
    Private Const WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START + 5
    Private Const WM_CAP_SET_SCALE = WM_CAP_START + 53
    Private Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
    Sub New(ByVal I As PictureBox)
        o = I
    End Sub
    Dim o As PictureBox
    Dim M_Handle As IntPtr

    Private Const WM_CAP_EDIT_COPY = (WM_CAP_START + 30)
    Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Integer)
    Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" _
    Alias "capCreateCaptureWindowA" (ByVal lpszWindowName As String, _
    ByVal dwStyle As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
    ByVal nHeight As Integer, ByVal hWndParent As Integer, ByVal nID As Integer) As Integer
    Private Const WS_CHILD = &H40000000
    Private Const WS_VISIBLE = &H10000000
    Private Const WM_USER = &H400

    Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Integer, _
    ByVal wMsg As Integer, ByVal wParam As Integer, _
    ByVal lParam As String) As Integer


    Public Function GrabImage() As Bitmap
        'paht:要保存bmp文件的路径 

        SendMessage(M_Handle, WM_CAP_EDIT_COPY, 0, 0)
        Return Clipboard.GetImage
    End Function
    Function CreateCaptureWindow(ByVal hWndParent As PictureBox, _
        Optional ByVal x As Integer = 0, Optional ByVal y As Integer = 0, _
        Optional ByVal nWidth As Integer = 320, Optional ByVal nHeight As Integer = 240, _
        Optional ByVal nCameraID As Integer = 0) As Integer
        Dim Preview_Handle As Integer
        Preview_Handle = capCreateCaptureWindow("Video", _
        WS_CHILD + WS_VISIBLE, x, y, _
        hWndParent.Width, hWndParent.Height, hWndParent.Handle, 0)
        Dim BOOL As Boolean
        BOOL = SendMessage(Preview_Handle, WM_CAP_DRIVER_CONNECT, nCameraID, 0) 'ncameraid(视频只有一个为0,多个以此类推)
        If (BOOL = False) Then
            MsgBox("没有找到视频设备!")
        End If
        SendMessage(Preview_Handle, WM_CAP_SET_PREVIEWRATE, 30, 0)
        SendMessage(Preview_Handle, WM_CAP_SET_OVERLAY, 1, 0)
        SendMessage(Preview_Handle, WM_CAP_SET_PREVIEW, 1, 0)
        M_Handle = Preview_Handle
    End Function

    Dim blnRunning As Boolean = False
    Public Sub Disconnect()
        SendMessage(M_Handle, WM_CAP_DRIVER_DISCONNECT, 0, 0)
    End Sub
    Dim blnRecording As Boolean = False

    '录像 
    Public Sub KineScope(ByVal path As String)
        If blnRecording Then
            Return
        Else
            blnRecording = True
        End If

        'path:要保存avi文件的路径 
        Dim hBmp As IntPtr = Marshal.StringToHGlobalAnsi(path)
        SendMessage(M_Handle, WM_CAP_FILE_SET_CAPTURE_FILEA, 0, hBmp.ToInt64())
        SendMessage(M_Handle, WM_CAP_SEQUENCE, 0, 0)
    End Sub
    Public Sub StopKinescope()
        If blnRecording Then
            SendMessage(M_Handle, WM_CAP_STOP, 0, 0)
        End If
        blnRecording = False
    End Sub
End Class

‘以上是视频接口类

VB程序窗体程序如下:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        L.CreateCaptureWindow(PictureBox1)
    End Sub

拍照可以用这个方法
        Me.PictureBox2.BackgroundImage = L.GrabImage()
保存可以用这个方法
        PictureBox2.BackgroundImage.Save(System.IO.Directory.GetCurrentDirectory & "\database\tp\" & i & ".jpg")
注:是这样,picturebbox1是视频显示,picturebbox2是拍取到的照片,你应该能用得上