Home Image-Pro Plus Automation with Macros

IpDocGetLine and IpDocGetArea in VB.Net

(Originally posted by ytsejamr on 8/13/2007)

Hi there,

I'm having some difficulty with the aforementioned functions in my program I'm developing in VB.Net (2005)

Here's an example:

Din dInfo as IPDOCINFO

Dim imgBuf(dInfo.Width*3-1, dInfo.Height-1) as Byte

ret = IpDocGetArea(DOCSEL_ACTIVE, dInfo.Extent, imgBuf(0, 0), CPROG)

For i As Integer = 0 To imgBuf.GetUpperBound(1)
    For j As Integer = 0 To imgBuf.GetUpperBound(0)

Now when I run the above code, it looks like the RGB values in the imgBuf variable are transposed somehow. I assumed data would be R1G1B1R2G2B2.....etc for each horizontal line in the image. It looks like it's putting each line of RGB values "vertically"

R1 R161
G1 G161
B1 B161
R2 R162
G2 G162
B2 B162
.  .
.  .
.  .

And what might be a similar problem. I tried reading in the image data using IpDocGetLine as follows:

Dim docInst As Integer = IpDocOpenAoi(DOCSEL_ACTIVE, IMA_RD)
Dim LineBuf(dInfo.Width * 3 - 1) As Byte

For i As Integer = 0 To dInfo.Height - 1
    ret = IpDocGetLine(docInst, i, LineBuf(0))
ret = IpDocCloseVri(docInst)

When I run this code, my LineBuf variable only has data every other index. (R1,0,G1,0,B1,0,R2,0,G2,0,B2 . . . etc)

I have the two functions declared in the ipc32.vb file as follows:

Declare Function IpDocGetLine Lib "IPC32" (ByVal iiInst As Integer, ByVal LineNum As Short, ByRef LineBuf As Byte) As Integer
Declare Function IpDocGetArea Lib "IPC32" (ByVal DocId As Short, ByRef rArea As RECT, ByRef lpBuf As Byte, ByVal gMode As Short) As Integer

I'm getting lost here. My main goal is to get the bitmap data of the current image into a array of bytes that I can then use with the .Net System.Drawing.Bitmap class.

I hope this kind of makes sense. It's tough to explain . . .


  • Options
    edited June 2013

    (Originally posted by YuriG on 8/15/2007)

    You have to use Integer type for line buffer (you used Byte). Please test the following macro that inverts red channel of the active image:

    Sub InvertRedChannel()
    	Dim i As Integer
    Dim j As Integer
    Dim imInfo As IPDOCINFO
    Dim docInst As Long
    If docInst=0 Then
    	MsgBox "Error open"
    	Exit Sub
    End If
    ret = IpDocGet(GETDOCINFO, DOCSEL_ACTIVE, imInfo)
    ReDim LineBuf(1 To imInfo.Width * 3) As Integer
    For j=1 To imInfo.Height
         For i=1 To imInfo.Width * 3 Step 3
         LineBuf(i) = 255-LineBuf(i)
         Next i
    Next j
    ' close the instance.
    ' refresh the display of the active document.
    End Sub
Sign In or Register to comment.