How to save a image using imagedata (C++ sample to

I have a sample application written in C++ for a slap scanner. I am able to get the image scanned but do not know what to do with the data received. Can anybody guide me in the right direction?

I have attached the SaveImage Code from the sample app(Written in C++) and would like to know how convert it to I am novice when it comes to C++.

I have tried to read the bytes from memory starting at the pointer returned to the tagImageData structure during the scanning process.

here is the structure that contains the image data:
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> Public Structure tagImageData
        Public Buffer As IntPtr '< Pointer to image buffer
        Public Width As UInteger       '< Image horizontal size
        Public Height As UInteger      '< Image vertical size
        Public ResolutionX As Double  '< Horizontal image resolution (in PPI)
        Public ResolutionY As Double  '< Vertical image resolution (in PPI)
        Public FrameTime As Double    '< Image acquisition time (in seconds)
        '< This value contains the time taken for acquisition
        '< from device (excluding processing time).
        Public Pitch As Integer       '< Image line pitch (in Bytes).
        '  Positive values indicate top down line order,
        '  Negative values mean bottom up line order
        Public BitsPerPixel As Byte   '< Number of Bits per pixel
        Public Format As Integer      '< Image color format
        Public IsFinal As Boolean     '< Marks image as finally processed
        '  A value of "FALSE" disqualifies image for further processing.
        '  (e.g. interim or preprocessed result images)
    End Structure
Werner PretoriusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Werner PretoriusAuthor Commented:
I managed to solve the problem myself using the following code:

    Public Sub OnResultImageAvailable(ByVal deviceHandle As IntPtr, ByVal pContext As IntPtr, ByVal imageStatus As Integer, ByVal image As tagImageData, ByVal imageType As Integer, ByVal detectedObjects As Integer)
            '**************read the image buffer from memory
            Dim index As Integer = image.Buffer 'set startIndex from where memory should be read
            Dim b As Byte
            Dim iBytesToRead As Integer = image.Width * image.Height - 1 'calculate the ammount of bytes to be read
            Dim buffer(iBytesToRead) As Byte 'create byte array based on iBytesToRead
            Dim i As Integer = 0
            Do While i < iBytesToRead
                b = Marshal.ReadByte(index)
                buffer.SetValue(b, i)
                index = index + 1
                i = i + 1
            '**************read the image buffer from memory

            '**************convert the byte array to bitmap image
            Dim bmp As New Bitmap(image.Width, image.Height, PixelFormat.Format8bppIndexed)

            'define a grayscale palette
            Dim palette As ColorPalette = bmp.Palette
            Dim j As Integer
            For j = 0 To 255
                palette.Entries(j) = Color.FromArgb(255, j, j, j)
            bmp.Palette = palette

            'copy bytes to bitmap data region
            Dim RECT As New Rectangle(0, 0, image.Width, image.Height)
            Dim bmpData As BitmapData = bmp.LockBits(RECT, ImageLockMode.WriteOnly, bmp.PixelFormat)

            'set the pointer
            Dim ptr As IntPtr = bmpData.Scan0

            Dim numberOfBytes As Integer = bmpData.Stride * bmp.Height

            Marshal.Copy(buffer, 0, ptr, numberOfBytes)
            '**************convert the byte array to bitmap image

            'flip the upside down image

            'display the image
            PictureBox1.Image = bmp

        Catch ex As Exception

        End Try
        MsgBox("Result Image Available")
    End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Werner PretoriusAuthor Commented:
I managed to solve the problem myself. I was reading the memory until i reach a null value at first. I decided to read the memory for (width * height ) number of bytes and that seemed to do the trick
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.