5
Contributors
8
Replies
11
Views
7 Years
Discussion Span
Last Post by rajansoni
0

i got this following code for cam

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Jpeg compression quality 
        Dim nQuality As Short = 45

        'Shout a picture from my webcam 
        Dim cam As CAMSERVERLib.Camera = New CAMSERVERLib.CameraClass()

        Dim picture As Byte() = CByte(cam.GrabFrame(nQuality))

        'Add the hour to the jpeg picture 
        Dim ms As New MemoryStream(picture)
        Dim bmp As New Bitmap(ms)

        Dim g As Graphics = Graphics.FromImage(bmp)

        Dim strDate As String = DateTime.Now.ToLongDateString() + " - " + DateTime.Now.ToLongTimeString()

        Dim drawFormat As New StringFormat()
        drawFormat.Alignment = StringAlignment.Center

        g.DrawString(strDate, New Font(FontFamily.GenericSansSerif, 12), New SolidBrush(Color.Black), New RectangleF(1, 1, 320, 240), drawFormat)

        g.DrawString(strDate, New Font(FontFamily.GenericSansSerif, 12), New SolidBrush(Color.White), New RectangleF(0, 0, 320, 240), drawFormat)

        'Get codecs 
        Dim icf As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()

        Dim encps As New EncoderParameters(1)
        Dim encp As New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, CLng(nQuality))

        'Set quality 
        encps.Param(0) = encp

        bmp.Save(Response.OutputStream, icf(1), encps)

        g.Dispose()
        bmp.Dispose()
    End Sub

but there is an error pointing towards the highlited region saying type camserverlib.camera is not defined. can you'll plz let me know the alternative for or an altenative code........please

0

i got this following code for cam

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Jpeg compression quality 
        Dim nQuality As Short = 45

        'Shout a picture from my webcam 
        Dim cam As CAMSERVERLib.Camera = New CAMSERVERLib.CameraClass()

        Dim picture As Byte() = CByte(cam.GrabFrame(nQuality))

        'Add the hour to the jpeg picture 
        Dim ms As New MemoryStream(picture)
        Dim bmp As New Bitmap(ms)

        Dim g As Graphics = Graphics.FromImage(bmp)

        Dim strDate As String = DateTime.Now.ToLongDateString() + " - " + DateTime.Now.ToLongTimeString()

        Dim drawFormat As New StringFormat()
        drawFormat.Alignment = StringAlignment.Center

        g.DrawString(strDate, New Font(FontFamily.GenericSansSerif, 12), New SolidBrush(Color.Black), New RectangleF(1, 1, 320, 240), drawFormat)

        g.DrawString(strDate, New Font(FontFamily.GenericSansSerif, 12), New SolidBrush(Color.White), New RectangleF(0, 0, 320, 240), drawFormat)

        'Get codecs 
        Dim icf As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()

        Dim encps As New EncoderParameters(1)
        Dim encp As New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, CLng(nQuality))

        'Set quality 
        encps.Param(0) = encp

        bmp.Save(Response.OutputStream, icf(1), encps)

        g.Dispose()
        bmp.Dispose()
    End Sub

but there is an error pointing towards the highlited region saying type camserverlib.camera is not defined. can you'll plz let me know the alternative for or an altenative code........please

U NEED TO REGISTER CAMSERVER.DLL LJ15.DLL IN C:\WINDOWS TO EXECUTE THE ABOVE CODE(first drag nd drop those dll's in c:\windows)


U CAN REGISTER IT IN RUN using the below commands

regsvr32 camserver.dll
regsvr32 lj15.dll

0

when i am trying to register the to regsvr32 camserver.dll in the run program, it's giving an error as follows
loadlibrary("camserver.dll) failed-specified module could not be found

0

i'm trying this code past few days and still not getting through it. so i need your help desperately. just tell me where i'm wrong in the given following code. and I need it very urgently

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Linq
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Runtime.InteropServices.ComTypes

Namespace WebCamera
    Public Class Class1
        'Implements IDisposable
        ' Those contants are used to overload the unmanaged code functions
        ' * each constant represent a state


        Private Const WM_CAP As Short = &H400
        Private Const WM_CAP_DRIVER_CONNECT As Integer = &H40A
        Private Const WM_CAP_DRIVER_DISCONNECT As Integer = &H40B
        Private Const WM_CAP_EDIT_COPY As Integer = &H41E
        Private Const WM_CAP_SET_PREVIEW As Integer = &H432
        Private Const WM_CAP_SET_OVERLAY As Integer = &H433
        Private Const WM_CAP_SET_PREVIEWRATE As Integer = &H434
        Private Const WM_CAP_SET_SCALE As Integer = &H435
        Private Const WS_CHILD As Integer = &H40000000
        Private Const WS_VISIBLE As Integer = &H10000000
        Private Const SWP_NOMOVE As Short = &H2
        Private SWP_NOZORDER As Short = &H4
        Private HWND_BOTTOM As Short = 1

        'This function enables enumerate the web cam devices
        <DllImport("avicap32.dll")> _
        Protected Shared Function capGetDriverDescriptionA(ByVal wDriverIndex As Short, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef lpszName As [String], ByVal cbName As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef lpszVer As [String], ByVal cbVer As Integer) As Boolean
        End Function

        'This function enables create a window child with so that you can display it in a picturebox for example
        <DllImport("avicap32.dll")> _
        Protected Shared Function capCreateCaptureWindowA(<MarshalAs(UnmanagedType.VBByRefStr)> ByRef 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
        End Function

        'This function enables set changes to the size, position, and Z order of a child window
        <DllImport("user32")> _
        Protected Shared Function SetWindowPos(ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, _
        ByVal wFlags As Integer) As Integer
        End Function

        'This function enables send the specified message to a window or windows
        <DllImport("user32", EntryPoint:="SendMessageA")> _
        Protected Shared Function SendMessage(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, <MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer
        End Function

        'This function enable destroy the window child 
        <DllImport("user32")> _
        Protected Shared Function DestroyWindow(ByVal hwnd As Integer) As Boolean
        End Function

        ' Normal device ID
        Private DeviceID As Integer = 0
        ' Handle value to preview window
        Private hHwnd As Integer = 0
        'The devices list
        Private ListOfDevices As New ArrayList()

        'The picture to be displayed
        Private _Container As Image
        Public Property Container() As Image
            Get
                Return _Container
            End Get
            Set(ByVal value As Image)
                _Container = value
            End Set
        End Property

        ' Connect to the device.
        ''' <summary>
        ''' This function is used to load the list of the devices 
        ''' </summary>
        Public Sub Load()
            Dim Name As String = [String].Empty.PadRight(100)
            Dim Version As String = [String].Empty.PadRight(100)
            Dim EndOfDeviceList As Boolean = False
            Dim index As Short = 0

            ' Load name of all avialable devices into the lstDevices .
            Do
                ' Get Driver name and version
                EndOfDeviceList = capGetDriverDescriptionA(index, Name, 100, Version, 100)
                ' If there was a device add device name to the list
                If EndOfDeviceList Then
                    ListOfDevices.Add(Name.Trim())
                End If
                index += 1
            Loop While Not (EndOfDeviceList = False)
        End Sub

        ''' <summary>
        ''' Function used to display the output from a video capture device, you need to create 
        ''' a capture window.
        ''' </summary>
        Public Sub OpenConnection()
            Dim DeviceIndex As String = Convert.ToString(DeviceID)
            Dim oHandle As IntPtr = Container.Height

            If True Then
                MsgBox("You should set the container property")
            End If

            ' Open Preview window in picturebox .
            ' Create a child window with capCreateCaptureWindowA so you can display it in a picturebox.

            hHwnd = capCreateCaptureWindowA(DeviceIndex, WS_VISIBLE Or WS_CHILD, 0, 0, 640, 480, _
            oHandle.ToInt32(), 0)

            ' Connect to device
            If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, DeviceID, 0) <> 0 Then
                ' Set the preview scale
                SendMessage(hHwnd, WM_CAP_SET_SCALE, -1, 0)
                ' Set the preview rate in terms of milliseconds
                SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)

                ' Start previewing the image from the camera
                SendMessage(hHwnd, WM_CAP_SET_PREVIEW, -1, 0)

                ' Resize window to fit in picturebox

                ' Error connecting to device close window
                SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, Container.Height, Container.Width, _
                SWP_NOMOVE Or SWP_NOZORDER)
            End If
        End Sub

        'Close windows
        Private Sub CloseConnection()

            SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, DeviceID, 0)
            ' close window
            DestroyWindow(hHwnd)
        End Sub
       End Class
End Namespace

the above one is written in the class and the other part is written in the form load

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        oWebCam = New WebCamera.Class1()
        oWebCam.Container = Image1
    End Sub
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        oWebCam.OpenConnection()
        oWebCam.Load()
    End Sub

plz tell where i'm wrong in the code
i need it very urgently
plz reply

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.