How to access Image from a memory ?

Greetings!

I'm scanning image and the api stores an image into a memory. I would like to access that image and store in a hard disk. Can anyone have a working example/reference on the web.

Cheers
YamihO
LVL 1
yamihoAsked:
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.

chaniewskimCommented:
What kind of API are you using?
0
yamihoAuthor Commented:
Its a Fuji Machine Systems DLL used for scanning cheque images. Once you scan the cheque it'll store the image in the memory, so i got to copy to the hard disk.
0
AlexFMCommented:
And what is the image format?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

yamihoAuthor Commented:
I would like to store in a TIFF Format..

Please have a look at the documentation provided by the API Vendor..


=========================
fsmSortGetFrontMemory, fsmSortGetBackMemory

NOTE:  fsmSortGetFrontMemory should only be called by the above mentioned call back functions.
NOTE:  fsmSortGetBackMemory should only be called by the above mentioned call back functions.

Get the memory locations for the front from struct SortCallBack pointed to by lParam.  fsnSortGetBackMemory gets the memory location for the back image.
NOTE:  It is the user’s responsibility to allocate enough memory for the images.  We suggest 128,000 for TIFF (bitonal, black/white images) and 8 * 128,000 for gray scale (JPEG, 25% quality).  Obviously, these are extremely generous sizes for the files.  Smaller will work but we do not guarantee the results.  

NOTE:  On the 5180 when fsmScanImageFirst is called, the image call back function will return the image in memory.
Syntax

#include <fsmfuji.h>

char * PASCAL fsmSortGetFrontMemory(long lParam, long *plFrontSize)
char * PASCAL fsmSortGetBackMemory(long lParam, long *plBackSize)


Description

Gets the memory pointers for the document from struct SortCallBack pointed to by lParam.

Arguments

lParam            lParam passed to the call back function.  Pass lParam in the call back function directly to this function without modification.

plFrontFileSize             Size in bytes of front image in memory.
plBackFileSize             Size in bytes of back image in memory.

Returns

Return functions points to pcFront or memory location for the front image or pcBack or memory location for the back image.  If return is NULL, then no image is available in memory or if  *plFrontSize or *plBackSize = 0, then an image is not available.


NULL             Image memory not found or not valid.


Functions Called

NONE


0
yamihoAuthor Commented:
The API vendor has given an example but that is in VB6.0. I'm attaching that as well. It works fine in classic vb, but i've no clue how to convert to vb.net :(


---------------------------------
'// Saves an image from memory
Public Function SaveImage(ByVal strFileName$, ByVal lngMem&, ByVal lngBytes&) As Long

    Dim lngFile&
    Dim lngTemp&
   
    On Error Resume Next
   
    '// Create the file always and w/Normal Attribute.
'    lngFile = CreateFile(strFileName, GENERIC_WRITE, FILE_SHARE_READ, ByVal 0&, _
                         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0&)
    '// Create the file always and w/Normal Attribute.
   
    lngFile = CreateFile(strFileName, GENERIC_WRITE, FILE_SHARE_READ, 0, _
                         CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, 0)
    If lngFile = INVALID_HANDLE_VALUE Then
        SaveImage = -801 '// FSM Error opening TIFF/file
        Exit Function
    End If
   
    '// Write the image to the file
    If (WriteFile(lngFile, ByVal lngMem, lngBytes, lngTemp, ByVal 0&) = 0) Then
        SaveImage = -803 '// FSM Error writing to TIFF/file
    End If

    CloseHandle (lngFile)

End Function
0
tgannettsCommented:
It should just be a case of updating VB6.0 data types to .NET data types, for example replacing VB6.0 Long with VB.NET int32, and making sure everything is marshalled correctly...

Can you show the VB6.0 declaration for the CreateFile function.

Tom
0
yamihoAuthor Commented:
Declarations for vb6.0
------------------------

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal strFileName$, ByVal dwDesiredAccess&, ByVal dwShareMode&, ByVal lpSecurityAttributes&, ByVal dwCreationDisposition&, ByVal dwFlagsAndAttributes&, ByVal hTemplateFile&) As Long

Private Declare Function WriteFile Lib "kernel32" (ByVal hFile&, lpBuffer As Any, ByVal nNumberOfBytesToWrite&, lpNumberOfBytesWritten&, ByVal lpOverlapped As Any) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject&) As Long

Can we convert these datatypes to VB.NET? Can you give me working example please..
0
tgannettsCommented:
I haven't tested these but I think the following should work:

Imports System.Runtime.InteropServices

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (<MarshalAs(UnmanagedType.LPStr)> ByVal strFileName As String, ByVal dwDesiredAccess As Int32, ByVal dwShareMode as Int32, ByVal lpSecurityAttributes As Int32, ByVal dwCreationDisposition As Int32, ByVal dwFlagsAndAttributes As Int32, ByVal hTemplateFile As Int32) As Int32

Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Int32, <MarshalAs(UnmanagedType.AsAny)> ByVal lpBuffer As Object, ByVal nNumberOfBytesToWrite As Int32, ByVal lpNumberOfBytesWritten As Int32, <MarshalAs(UnmanagedType.AsAny)> ByVal lpOverlapped As Object) As Int32

Tom.
0
tgannettsCommented:
oh, and

Private Declare Function CloseHandle Lib "kernel32" (Byval hObject as int32) as int32
0
yamihoAuthor Commented:
Ok Tom,

we are almost there. Now the file is getting created in the hard disk, but this WriteFile function is unable to capture image.

            '// Write the image to the file
            If (WriteFile(lngFile, lngMem, lngBytes, lngTemp, 0) = 0) Then
                Return -803 '// FSM Error writing to TIFF/file
            End If

The WriteFile Function is returning "0" and function is Returning -803. Do u think i'm doing something wrong...

Have a look at the vb6.0 function again. It is written "ByVal 0&" as "lpOverlapped as Object". I've no clue what value will go in and how about you ?

'// Write the image to the file
    If (WriteFile(lngFile, ByVal lngMem, lngBytes, lngTemp, ByVal 0&) = 0) Then
        SaveImage = -803 '// FSM Error writing to TIFF/file
    End If
0
tgannettsCommented:
Try using the following:

Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Int32, ByVal lpBuffer As Int32, ByVal nNumberOfBytesToWrite As Int32, ByVal lpNumberOfBytesWritten As Int32, ByVal lpOverlapped As int32) As Int32

Tom

0
tgannettsCommented:
And call it using the following statement:

if(WriteFile(lngFile, lngMem, lngBytes, lngTemp, 0) = 0 then

...

Tom.
0
yamihoAuthor Commented:
Hi Tom,

I got an image captured. But a very small problem raised now.

I'm getting this error while calling WriteFile Function.

I'm writing :

If (WriteFile(lngFile, lngMem, lngBytes, lngTemp, 0) = 0) Then

Error Description:
"Object reference not set to an instance of an object'

Thanks a lot for spending time with me..
Fix this last one..
Cheers
0
tgannettsCommented:
I think you might need to replace 'Byval lpNumberofBytesWritten as int32' to ByRef lpNumberofBytesWritten as int32' The API will return a value in this parameter telling you how bytes have been written to the file.

Tom.
0

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
yamihoAuthor Commented:
Tom,

I've no idea how to thank you man. Well, a very big Thank you for this help. I really appreciate it. It works perfectly alright.

Thank you so much.

Cheers
YAMIHO
0
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.