Solved

How to access Image from a memory ?

Posted on 2004-04-22
15
405 Views
Last Modified: 2010-04-24
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
0
Comment
Question by:yamiho
15 Comments
 
LVL 5

Expert Comment

by:chaniewskim
ID: 10886410
What kind of API are you using?
0
 
LVL 1

Author Comment

by:yamiho
ID: 10886515
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 10886518
And what is the image format?
0
 
LVL 1

Author Comment

by:yamiho
ID: 10886534
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
 
LVL 1

Author Comment

by:yamiho
ID: 10886552
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
 
LVL 5

Expert Comment

by:tgannetts
ID: 10886661
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
 
LVL 1

Author Comment

by:yamiho
ID: 10886691
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 5

Expert Comment

by:tgannetts
ID: 10886916
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
 
LVL 5

Expert Comment

by:tgannetts
ID: 10886929
oh, and

Private Declare Function CloseHandle Lib "kernel32" (Byval hObject as int32) as int32
0
 
LVL 1

Author Comment

by:yamiho
ID: 10887071
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
 
LVL 5

Expert Comment

by:tgannetts
ID: 10887239
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
 
LVL 5

Expert Comment

by:tgannetts
ID: 10887255
And call it using the following statement:

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

...

Tom.
0
 
LVL 1

Author Comment

by:yamiho
ID: 10887387
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
 
LVL 5

Accepted Solution

by:
tgannetts earned 500 total points
ID: 10887422
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
 
LVL 1

Author Comment

by:yamiho
ID: 10887455
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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now