playing weird video pixels in framework 4

2013-03-31
2014-03-27
  • Ahmed Mobarako
    Ahmed Mobarako
    2013-03-31

    in direct show some of flv videos playes very weird in vb.net 2010

    but when i change the programming targeted framework from 4.0 to 3.5 it play normmaly

    any ideas

     
    • Eric
      Eric
      2013-04-03

      Can you define what you mean by "playes very weird" ?

       
  • Ahmed Mobarako
    Ahmed Mobarako
    2013-04-13

    like a lot of slow black pixels shadows showed in the movies

    and when i change the targeted .NET framework to version 3.5

    it plays perfect but i can't use the new .NET 4.0 features

    and by the way i don't know what filters is

    i just play media from filtergraph interface by using

    the graphBuilder.RenderFile(filepath, Nothing) method

     
    Last edit: Ahmed Mobarako 2013-04-13
    • Eric
      Eric
      2013-04-15

      I don't know how your code look like but normaly, with DirectShowLib, you just allocate COM objects and interact with them. Except if you implemented a filter (or a DMO) in .NET, I don't see how changing the version could interact with your video display.

      Are you sure that your problem is not related to a x86/x64 problem ?

       
    • TheShanMan
      TheShanMan
      2014-03-27

      I'm having this exact problem at the moment. It doesn't matter if I use the prebuilt library or rebuild it against various .net versions and/or cpu targets. This happens in the DxPlay sample too, so it's not just my app. I'm on Win7 x64 FWIW, and I'm testing with a .mov file. If I target 3.5 with the sample, it works fine. So whether it's the library or the sample, I'm not sure. My app is borrowing heavily from DxPlay so it could certainly be a bug in DxPlay, although nothing stands out to me as I look through the code.

      I also get an SEHException when my app closes if I've played a video. That doesn't happen in DxPlay but I'm guessing (hoping) when the main problem is solved, this will go away.

       
  • Ahmed Mobarako
    Ahmed Mobarako
    2013-04-16

    no i'am on x86 ( 32 bit ) and i don't even set my targeting cpy to ( any cpu 'both x86/x64 )

    i always set it to x86 programing and i use windows 7

    it drives me crazy

    and here is my module to play files

    Imports System
    Imports System.Collections
    Imports System.ComponentModel
    Imports System.Drawing
    Imports System.Runtime.InteropServices
    Imports System.Windows.Forms
    Imports DirectShowLib ' add refrence to direct show lib ( a .dll file )

    Module Module1

    Public Class DirectShowMedia
        Implements IDisposable
        Private Declare Auto Function BitBlt Lib "GDI32.DLL" (ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As Int32) As Boolean
    
        Public Sub Dispose() Implements IDisposable.Dispose
            CloseClip()
        End Sub
    
        Public Enum moviestatus
            stop_ = 0
            play = 1
            pause = 2
        End Enum
    
        Private Enum PlayState
            Stopped
            Paused
            Running
            Init
        End Enum
    
        Private Enum MediaType
            Audio
            Video
        End Enum
    
        Private Const WMGraphNotify As Integer = 13
        Private Const VolumeFull As Integer = 0
        Private Const VolumeSilence As Integer = -10000
    
        Private graphBuilder As IGraphBuilder = Nothing
        Private mediaControl As IMediaControl = Nothing
        Private mediaEventEx As IMediaEventEx = Nothing
        Private videoWindow As IVideoWindow = Nothing
        Private basicAudio As IBasicAudio = Nothing
        Private basicVideo As IBasicVideo2 = Nothing
        Private mediaSeeking As IMediaSeeking = Nothing
        Private mediaPosition As IMediaPosition = Nothing
        Private frameStep As IVideoFrameStep = Nothing
        Dim hr As Integer = 0
        Private filename As String
        Private isAudioOnly As Boolean = False
        Private isFullScreen As Boolean = False
        Private currentVolume As Integer = VolumeSilence
        Private currentState As PlayState = PlayState.Stopped
        Private currentPlaybackRate As Double = 1.0
        Private UseHand As IntPtr
        Private FsDrain As IntPtr = IntPtr.Zero
        Private can_seek As OABool
        Public Event MedClose()
    

    If DEBUG Then

        Private rot As DsROTEntry = Nothing
    

    End If

        Private controlholder As PictureBox
    
        ''' <summary>
        ''' Open the video to the specified Container Control e.g: picturebox
        ''' </summary>
        ''' <param name="fName">file path to video file </param>
        ''' <param name="control">container to hold the video </param>
        ''' <remarks></remarks>
    
        Public Sub OpenFile(ByVal fName As String, ByRef control As PictureBox)
            ' Make sure everything is closed
            CloseClip()
            controlholder = control
            UseHand = controlholder.Handle 'Handle to Display Video if any
    
            AddHandler controlholder.Disposed, AddressOf Dispose
            AddHandler control.Resize, AddressOf SetVideoSize
            filename = fName
            currentState = PlayState.Stopped 'Reset State to Stopped
    
        End Sub
    
        Public Sub PlayMedia()
            Dim fname As String = filename
            Dim hr As Integer = 0
            If fname = "" Then Exit Sub
            Try
    
                graphBuilder = DirectCast(New FilterGraph, IFilterGraph2) 'Load Graph Builder Device
    
                hr = graphBuilder.RenderFile(fname, Nothing) ' Initialize Graph Builder
                DsError.ThrowExceptionForHR(hr)
    
                'Load all Interfaces we will use
                mediaControl = DirectCast(graphBuilder, IMediaControl)
                mediaEventEx = DirectCast(graphBuilder, IMediaEventEx)
                mediaSeeking = DirectCast(graphBuilder, IMediaSeeking)
                mediaPosition = DirectCast(graphBuilder, IMediaPosition)
                videoWindow = DirectCast(graphBuilder, IVideoWindow)
                basicVideo = DirectCast(graphBuilder, IBasicVideo2)
                basicAudio = DirectCast(graphBuilder, IBasicAudio)
                frameStep = DirectCast(graphBuilder, IVideoFrameStep)
                ' check type ( video or audio )
                Dim lVisible As OABool
    
                'If Interface is Nothing then Media is Audio
                If basicVideo Is Nothing Or videoWindow Is Nothing Then
                    isAudioOnly = True
                Else
                    isAudioOnly = False
                End If
    
                'Another way to test if Audio or Video
                hr = videoWindow.get_Visible(lVisible)
                If hr < 0 Then
                    isAudioOnly = True
                End If
    
                ' end check type
    
                If Not isAudioOnly Then
                    'Notfy Window of Video
                    hr = mediaEventEx.SetNotifyWindow(UseHand, WMGraphNotify, IntPtr.Zero)
                    DsError.ThrowExceptionForHR(hr)
    
                    'Set Owner to Display Video
                    hr = videoWindow.put_Owner(UseHand)
                    DsError.ThrowExceptionForHR(hr)
    
                    'Set Owner Video Style
                    hr = videoWindow.put_WindowStyle(WindowStyle.Child And WindowStyle.ClipSiblings And WindowStyle.ClipChildren)
                    DsError.ThrowExceptionForHR(hr)
    
                End If
    

    If DEBUG Then

                rot = New DsROTEntry(graphBuilder)
    

    End If

                'Start Media
    
                hr = mediaControl.Run
                DsError.ThrowExceptionForHR(hr)
    
                currentState = PlayState.Running
    
                hr = videoWindow.put_MessageDrain(controlholder.Handle.ToInt32)
                DsError.ThrowExceptionForHR(hr)
    
                hr = mediaPosition.CanSeekForward(can_seek)
                DsError.ThrowExceptionForHR(hr)
    
                If isAudioOnly = False Then
                    'Set Video Size
                    SetVideoSize()
                End If
    
                hr = basicAudio.put_Volume(-10000)
                DsError.ThrowExceptionForHR(hr)
    
            Catch ex As Exception
                MsgBox("Error " & ex.Message, MsgBoxStyle.Critical, "Mob Error")
                RaiseEvent MedClose()
            End Try
    
        End Sub
    
        Public Sub pauseMedia()
            Try
                mediaControl.Pause()
                currentState = PlayState.Paused
            Catch ex As Exception
                currentState = PlayState.Stopped
            End Try
        End Sub
    
        Public Sub ResumeMedia()
            Try
                mediaControl.Run()
                currentState = PlayState.Running
    
            Catch ex As Exception
                currentState = PlayState.Stopped
            End Try
    
        End Sub
    
        Public Sub StopMedia()
            Try
                mediaControl.Stop()
                mediaPosition.put_CurrentPosition(0)
                currentState = PlayState.Stopped
             Catch ex As Exception
                currentState = PlayState.Stopped
            End Try
    
        End Sub
    
        Private Sub CloseClip()
            Try
                Dim hr As Integer = 0
    
                'Reset all Properties to Default
                currentState = PlayState.Stopped
                isAudioOnly = True
                isFullScreen = False
                filename = ""
    
                'Call sub to Close and Release from memory
                'Release Window Handle, Reset back to Normal
                If isAudioOnly = False Then
                    hr = videoWindow.put_Visible(OABool.False)
                    DsError.ThrowExceptionForHR(hr)
    
                    hr = videoWindow.put_Owner(IntPtr.Zero)
                    DsError.ThrowExceptionForHR(hr)
                End If
    
                If Not mediaEventEx Is Nothing Then
                    hr = mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero)
                    DsError.ThrowExceptionForHR(hr)
                End If
    

    If DEBUG Then

                If Not rot Is Nothing Then
                    rot.Dispose()
                    rot = Nothing
                End If
    

    End If

                'Release everything from memory
                mediaEventEx = Nothing
                mediaSeeking = Nothing
                mediaPosition = Nothing
                mediaControl = Nothing
                basicAudio = Nothing
                basicVideo = Nothing
                videoWindow = Nothing
                frameStep = Nothing
                If Not graphBuilder Is Nothing Then Marshal.ReleaseComObject(graphBuilder)
                graphBuilder = Nothing
                GC.Collect()
    
                'Reset more properties
                currentState = PlayState.Init
    
            Catch ex As Exception
                MsgBox("Errpr " & ex.Message, MsgBoxStyle.Critical, "Mob Error")
                RaiseEvent MedClose()
            End Try
        End Sub
    
        ''' <summary>
        ''' get or set the current movie status
        ''' </summary>
        ''' <value>value as moviestatus </value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property current_Playing_status() As moviestatus
            Get
                Select Case currentState
                    Case PlayState.Running
                        Return moviestatus.play
                    Case PlayState.Paused
                        Return moviestatus.pause
                      Case Else
                        Return moviestatus.stop_
                End Select
    
            End Get
    
        End Property
    
        ''' <summary>
        ''' let the container that plays video caputer mouse keyboard events from video
        ''' mouse_Click event don't fire ( use mouse up instead )
        ''' </summary>
        ''' <value>Boolean Value to detremine if to send the events to the parent Container</value>
        ''' <returns>Boolean Value to detremine if events are sent to the parent Container</returns>
        ''' <remarks></remarks>
        Public Property SendEventsToContainer As Boolean
    
            Get
                Try
                    hr = videoWindow.get_MessageDrain(FsDrain)
                    DsError.ThrowExceptionForHR(hr)
                    If FsDrain = IntPtr.Zero Then Return False Else Return True
    
                Catch ex As Exception
                    Return False
                End Try
            End Get
            Set(value As Boolean)
                Try
                    If value Then
                        hr = videoWindow.put_MessageDrain(controlholder.Handle.ToInt32)
                        DsError.ThrowExceptionForHR(hr)
    
                    Else
                        hr = videoWindow.put_MessageDrain(IntPtr.Zero)
                        DsError.ThrowExceptionForHR(hr)
    
                    End If
                Catch ex As Exception
    
                End Try
            End Set
    
        End Property
    
        Public Property Mouse_pointer_over_video As Boolean
            Get
                Try
                    Dim OA As OABool
                    hr = videoWindow.IsCursorHidden(OA)
                    DsError.ThrowExceptionForHR(hr)
                    If OA = OABool.True Then Return True Else Return False
    
                Catch ex As Exception
                    Return False
                End Try
    
            End Get
            Set(value As Boolean)
                Try
    
                    Dim OA As OABool
    
                    If value Then OA = OABool.True Else OA = OABool.False
                    hr = videoWindow.HideCursor(OA)
                    DsError.ThrowExceptionForHR(hr)
    
                Catch ex As Exception
    
                End Try
            End Set
        End Property
    
        Public ReadOnly Property get_duration_inSec() As Double
            Get
                Try
                    Dim hr As Integer = 0
                    If filename = Nothing Then
                        Return 0
                    Else
                        If currentState = PlayState.Stopped Or currentState = PlayState.Paused Or currentState = PlayState.Init Then Return 0 : Exit Property
                        Dim MedDur As Long
    
                        hr = mediaSeeking.GetDuration(MedDur)
                        DsError.ThrowExceptionForHR(hr)
    
                        Return CInt(MedDur / 10 ^ 7)
                        MedDur = Nothing
                    End If
                Catch ex As Exception
                    MsgBox("Error " & Err.Description, MsgBoxStyle.Critical, "Mob Error")
                    Return 0
                    RaiseEvent MedClose()
                End Try
            End Get
        End Property
    
        ''' <summary>
        ''' duration / postion easy to read formate ( 00:33:10 / 2:15:00 )
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property get_duration_position() As String
            Get
                Try
                    Dim hr As Integer = 0
                    If filename = "" Then
                        Return ""
                    Else
                        If currentState = PlayState.Stopped Or currentState = PlayState.Paused Or currentState = PlayState.Init Then Return "" : Exit Property
                        Dim MedDur As Double
                        Dim MedPos As Double
                        Dim MedTime As String
    
                        hr = mediaPosition.get_Duration(MedDur)
                        DsError.ThrowExceptionForHR(hr)
    
                        hr = mediaPosition.get_CurrentPosition(MedPos)
                        DsError.ThrowExceptionForHR(hr)
    
                        MedTime = New TimeSpan(0, 0, MedPos).ToString & " - " & New TimeSpan(0, 0, MedDur).ToString
    
                        Return MedTime
                        MedPos = Nothing
                        MedDur = Nothing
                    End If
                Catch ex As Exception
                    MsgBox("Error " & Err.Description, MsgBoxStyle.Critical, "Mob Error")
                    Return ""
                    RaiseEvent MedClose()
                End Try
            End Get
        End Property
    
        Public Property position_inSec() As Double
    
            Get
                Try
                    Dim hr As Integer = 0
                    If filename = "" Then
                        Return 0
                    Else
                        If currentState = PlayState.Stopped Or currentState = PlayState.Paused Or currentState = PlayState.Init Then Return "" : Exit Property
                        Dim MedPos As Double
    
                        hr = mediaSeeking.GetCurrentPosition(MedPos)
                        DsError.ThrowExceptionForHR(hr)
    
                        Return (MedPos / 10 ^ 7)
                        MedPos = Nothing
                    End If
                Catch ex As Exception
                    MsgBox("Error " & Err.Description, MsgBoxStyle.Critical, "Mob Error")
                    Return 0
                    RaiseEvent MedClose()
                End Try
            End Get
    
            Set(value As Double)
                Try
                    Dim hr As Integer = 0, br As Long
                    If filename = "" Then Exit Property
                    If currentState = PlayState.Stopped Or currentState = PlayState.Paused Or currentState = PlayState.Init Then Exit Property
                    currentState = PlayState.Paused
                    If can_seek = OABool.True Then
                        value *= 10 ^ 7
    
                        hr = mediaSeeking.SetPositions(CLng(value), AMSeekingSeekingFlags.AbsolutePositioning, br, AMSeekingSeekingFlags.ReturnTime)
                        DsError.ThrowExceptionForHR(hr)
                    End If
                    currentState = PlayState.Running
                Catch ex As Exception
                    MsgBox("Error " & Err.Description, MsgBoxStyle.Critical, "Mob Error")
                    RaiseEvent MedClose()
                End Try
            End Set
        End Property
    
        Public Overloads Sub SetVideoSize()
            If currentState = PlayState.Running Or currentState = PlayState.Paused Then
                videoWindow.SetWindowPosition(0, 0, controlholder.Width, controlholder.Height)
            End If
        End Sub
    
        Public Overloads Sub SetVideoSize(ByVal left As Integer, ByVal top As Integer, ByVal width As Integer, ByVal height As Integer)
            If currentState = PlayState.Running Or currentState = PlayState.Paused Then
                videoWindow.SetWindowPosition(left, top, width, height)
            End If
        End Sub
    
        Public Overloads Sub SetVideoSize(ByVal nMultiplier As Integer, ByVal nDivider As Integer)
            Try
                Dim hr As Integer = 0
                Dim lHeight As Integer, lWidth As Integer
                'Get Video Size
                hr = basicVideo.GetVideoSize(lWidth, lHeight)
                If hr = DsResults.E_NoInterface Then Exit Sub
    
                'Change if Different Size is selected in menu(50%, 200%..)
                lWidth = lWidth * nMultiplier / nDivider
                lHeight = lHeight * nMultiplier / nDivider
    
                'Set Window Size video will play on
    
                'Set Video Position on Window
                hr = videoWindow.SetWindowPosition(0, 0, lWidth, lHeight)
    
            Catch ex As Exception
                MsgBox("Error " & ex.Message, MsgBoxStyle.Critical, "Mob Error")
                RaiseEvent MedClose()
            End Try
        End Sub
    
        Public Sub FullScreenSwitch()
            Try
                'Dont Bother with FullScreen if Playing just Audio
                If isAudioOnly Then Exit Sub
                Dim hr As Integer = 0
    
                If isFullScreen = False Then
    
                    'Get Message Drain
                    ' hr = videoWindow.get_MessageDrain(FsDrain)
                    'DsError.ThrowExceptionForHR(hr)
    
                    'Send Message Drain to My Handle to allow keypress to exit fullscreen
                    'hr = videoWindow.put_MessageDrain(UseHand)
                    'DsError.ThrowExceptionForHR(hr)
    
                    'Switch to Fullscreen Mode
                    hr = videoWindow.put_FullScreenMode(OABool.True)
                    DsError.ThrowExceptionForHR(hr)
    
                    isFullScreen = True
                Else
    
                    'Switch to Window Mode
                    hr = videoWindow.put_FullScreenMode(OABool.False)
                    DsError.ThrowExceptionForHR(hr)
    
                    'Set Message Drain back to Normal
                    ' hr = videoWindow.put_MessageDrain(FsDrain)
                    'DsError.ThrowExceptionForHR(hr)
    
                    isFullScreen = False
                End If
            Catch ex As Exception
                MsgBox("Error " & ex.Message, MsgBoxStyle.Critical, "Mob Error")
                RaiseEvent MedClose()
            End Try
        End Sub
    
        ''' <summary>
        ''' Volume is a value from Min -10000 to Max 0
        ''' </summary>
        ''' <value>value from Min -10,000 to Max 0 </value>
        ''' <returns>integer value from -10,000 to 0 </returns>
        ''' <remarks></remarks>
        Public Property Volume As Integer
    
            Get
    
                Try
    
                    Dim hr As Integer = 0
                    Dim a As Integer
                    basicAudio.get_Volume(a)
                    DsError.ThrowExceptionForHR(hr)
                    Return a
                Catch ex As Exception
                    Return VolumeSilence
                End Try
    
            End Get
            Set(value As Integer)
                Dim hr As Integer = 0
    
                'Volume is a value from Min -10000 to Max 0
                Try
                    hr = basicAudio.put_Volume(value)
                    DsError.ThrowExceptionForHR(hr)
    
                Catch ex As Exception
    
                End Try
            End Set
        End Property
    
        ''' <summary>
        ''' Sets New Playrate Min is 0.0 and Max is 3.0
        ''' </summary>
        ''' <param name="NewRate">Normal Speed is (1.0), half Speed (0.5), double (2.0) </param>
        ''' <remarks></remarks>
        Public Sub SetPlayRate(ByVal NewRate As Double)
            Try
                Dim hr As Integer = 0
    
                'Sets New Playrate Min is 0 and Max is 3
                currentPlaybackRate = NewRate
                hr = mediaPosition.put_Rate(currentPlaybackRate)
                DsError.ThrowExceptionForHR(hr)
            Catch ex As Exception
                MsgBox("Errpr " & ex.Message, MsgBoxStyle.Critical, "Mob Error")
                RaiseEvent MedClose()
            End Try
        End Sub
    
        ''' <summary>
        ''' get a snapshot from video container control  as bitmap
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetSnapShotimage() As Bitmap
    
            Dim src As PictureBox = controlholder
            'Get a Graphics Object from the form
            Dim rect As RectangleF = src.DisplayRectangle
            Dim srcPic As Graphics = src.CreateGraphics
            'Create a EMPTY bitmap from that graphics
            Dim srcBmp As New Bitmap(src.Width, src.Height, srcPic)
            'Create a Graphics object in memory from that bitmap
            Dim srcMem As Graphics = Graphics.FromImage(srcBmp)
    
            'get the IntPtr's of the graphics
            Dim HDC1 As IntPtr = srcPic.GetHdc
            'get the IntPtr's of the graphics
            Dim HDC2 As IntPtr = srcMem.GetHdc
    
            'get the picture 
            BitBlt(HDC2, 0, 0, rect.Width, rect.Height, HDC1, rect.X, rect.Y, 13369376)
    
            'Clone the bitmap so we can dispose this one 
            GetSnapShotimage = srcBmp.Clone()
    
            'Clean Up 
            srcBmp.Dispose()
            srcBmp = Nothing
            srcPic.ReleaseHdc(HDC1)
            srcMem.ReleaseHdc(HDC2)
            srcPic.Dispose()
            srcPic = Nothing
            srcMem.Dispose()
            srcMem = Nothing
        End Function
    
        ''' <summary>
        ''' get a snapshot from video container control  as byte array
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetSnapShotBytes() As Byte()
    
            Dim src As PictureBox = controlholder
    
            'Get a Graphics Object from the form
            Dim rect As RectangleF = src.DisplayRectangle
            Dim srcPic As Graphics = src.CreateGraphics
            'Create a EMPTY bitmap from that graphics
            Dim srcBmp As New Bitmap(src.Width, src.Height, srcPic)
            'Create a Graphics object in memory from that bitmap
            Dim srcMem As Graphics = Graphics.FromImage(srcBmp)
    
            'get the IntPtr's of the graphics
            Dim HDC1 As IntPtr = srcPic.GetHdc
            'get the IntPtr's of the graphics
            Dim HDC2 As IntPtr = srcMem.GetHdc
    
            'get the picture 
            BitBlt(HDC2, 0, 0, rect.Width, rect.Height, HDC1, rect.X, rect.Y, 13369376)
    
            'Save Image to Byte array function
    
            Dim memImage As New System.IO.MemoryStream
            Dim bytImage() As Byte
            Try
                srcBmp.Save(memImage, srcBmp.RawFormat)
            Catch
                srcBmp.Save(memImage, Imaging.ImageFormat.Jpeg)
            End Try
            bytImage = memImage.GetBuffer()
            memImage.Dispose()
    
            Return bytImage
    
            'Clean Up 
            srcBmp.Dispose()
            srcBmp = Nothing
            srcPic.ReleaseHdc(HDC1)
            srcMem.ReleaseHdc(HDC2)
            srcPic.Dispose()
            srcPic = Nothing
            srcMem.Dispose()
            srcMem = Nothing
        End Function
    
        Protected Overrides Sub Finalize()
            CloseClip()
            MyBase.Finalize()
        End Sub
    
        Public Sub New()
            CloseClip()
        End Sub
    End Class
    
    Public Function BytesToImage(ByVal ImageBytes() As Byte) As Image
        Try
    
            Dim imgNew As Image
            Dim memImage As New System.IO.MemoryStream(ImageBytes)
            imgNew = Image.FromStream(memImage)
            memImage.Dispose()
            Return imgNew
    
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    
    Public Function ImageToBytes(ByVal Image As Image) As Byte()
        Dim memImage As New System.IO.MemoryStream
        Dim bytImage() As Byte
        Try
            Image.Save(memImage, Image.RawFormat)
        Catch
            Image.Save(memImage, Imaging.ImageFormat.Jpeg)
        End Try
        bytImage = memImage.GetBuffer()
        memImage.Dispose()
        Return bytImage
    End Function
    

    End Module