Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to access Image from a memory ?

Posted on 2004-04-22
15
Medium Priority
?
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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