How to Get Image send by API

  • Thread starter Thread starter AAVarda
  • Start date Start date
A

AAVarda

Hi,
I have a device that scan's a doc and send's the doc image back. Below is
the function in API to get the Image:

ULONG MTMICRGetImage (
char *pcDevName,
char *pcImageID,
char *pcBuffer,
DWORD *pwdLength
);

Example of using the function
===================
//Get the imgae size from function DocInfo
//Get the imgae ID from function DocInfo

//Allocate memory for image
ImageBuffer = (char*) VirtualAlloc (NULL, bufferSize, MEM_COMMIT,
PAGE_READWRITE);

//Use function MTMICRGetDevice to get device name for variable "Device"
//Get image from the device
MTMICRGetImage (Device, cValue, ImageBuffer, &bufferSize);
 
Hi,

First I have to ask you a few questions:

- What's the "Image"? It it a text string, like description, or it's the
image (graphical)?
- Is the provided declaration located in docs or in C/C++ header file?
If it's in docs please provide the one in header.

And a few suggestions.

- If pcDevName and pcImageID are not going to be changed then declare
them as String rather then as StringBuilder. That's more handy!
- Try to declare pcBuffer as IntPtr (ByVal); then allocate memory using
Marshal.AllocHGlobal and call function with the buffer returned as an
argument. Then look in a memory window if image is actually put there,
and what does it looks like.

Roman
 
Image is Graphical.I will try the other solution and let you know what
happens..Thank you
 
Just to make things clear, below example of using the function was given in
the Device's programmers Manual

ULONG MTMICRGetImage (char *pcDevName,char *pcImageID,char *pcBuffer,DWORD
*pwdLength)
..
..
..
..
Example:
//Get the imgae size from function DocInfo
//Get the imgae ID from function DocInfo

//Allocate memory for image
ImageBuffer = (char*) VirtualAlloc (NULL, bufferSize, MEM_COMMIT,
PAGE_READWRITE);

//Use function MTMICRGetDevice to get device name for variable
"Device"
//Get image from the device
MTMICRGetImage (Device, cValue, ImageBuffer, &bufferSize);
 
AAVarda said:
Just to make things clear, below example of using the function was given
in the Device's programmers Manual

ULONG MTMICRGetImage (char *pcDevName,char *pcImageID,char *pcBuffer,DWORD
*pwdLength)
.
.
.
.
Example:
//Get the imgae size from function DocInfo
//Get the imgae ID from function DocInfo

//Allocate memory for image
ImageBuffer = (char*) VirtualAlloc (NULL, bufferSize, MEM_COMMIT,
PAGE_READWRITE);

//Use function MTMICRGetDevice to get device name for variable
"Device"
//Get image from the device
MTMICRGetImage (Device, cValue, ImageBuffer, &bufferSize);
.
.
.
//Free the memory
VirtualFree (ImageBuffer, bufferSize, MEM_DECOMMIT);
}

I wrote the above API function in VB .NET as mention below
=======================================
Declare Ansi Function fGetImage Lib "mtmcrapi.dll" Alias "MTMICRGetImage"
(ByVal NameSB As StringBuilder, ByVal sbValue As StringBuilder, ByVal
sbImageData As StringBuilder, ByRef intImageSize As Integer) As Integer

Dim sbImage As New StringBuilder(37346)
dim rst as integer
rst = fGetImage(nameSB, sbImageUrl, sbImage, intImageSize)
MessageBox.Show(rst.ToString & "=" & sbImage.ToString, "ImageFunction")

My Doubts
=========
The function is returning value 0 that means running fine and
sbImage.ToString returns 4 junk characters.
-According to the Manual Example what is the ImageBuffer HOLDING ???

That's the question. What image format does ImageBuffer hold ?
- a fileformat like bmp, gif, jpg etc or
- a DIB with a BITMAPINFO structure or
- only pixel data (then you need to know height, width, stride, colorformat
(RGB24, RGB16, etc)) and compression or
- maybe something else ...

Can't you find any clues in the documenation for the library ?

HTH,
Greetings
 
You should look into what manual says about using the image that is
retrieved by call to MTMICRGetImage. What happens to it after it's
retrieved?

You may also try to translate C example line by line, i.e. with
VirtualAlloc etc.

~
Friend Declare Function VirtualAlloc Lib "kernel32.dll" ( _
ByVal lpAddress As IntPtr, _
ByVal dwSize As Integer, _
ByVal flAllocationType As Integer, _
ByVal flProtect As Integer _
) As IntPtr

Friend Declare Function VirtualFree Lib "kernel32.dll" ( _
ByVal lpAddress As IntPtr, _
ByVal dwSize As Integer, _
ByVal dwFreeType As Integer _
) As Boolean
~

Roman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top