PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
byte array to picture -[RESOLVED]--VBForums
Results 1 to 30 of 30

Thread: byte array to picture -[RESOLVED]-

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    Resolved byte array to picture -[RESOLVED]-

    Hello All,

    Sorry to post this question again, I've tryied all code samples in the web and still can't get it done.

    I'm working with a fingerprint sensor, from the docs:

    "The fingerprint image captured from sensor can be uploaded/downloaded from RAM. The
    image is transfered as a binary sequence of 30400 byte values. The image has 152 columns (x)
    and 200 rows (y). The first byte in the sequence is the upper left pixel and continues in columndirection."

    So, I already have the byte array containing the 30400 bytes (I think it has only the data bytes, not header bytes indicating the type of image).

    I can not display the image in a picture box, even if I write the byte array to disk first...

    Please help..
    Last edited by Electroman; Nov 25th, 2004 at 07:46 PM.

  2. #2
    Lively Member vbgamer45's Avatar
    Join Date
    Sep 2004
    Posts
    67
    You can just draw each byte to the screen or the picture box using the pset function or point function.
    VB Code:
    1. Dim X as Integer
    2. Dim Y as Integer
    3. dim bArray() as Byte
    4. Redim bArray(1 to 152, 1 to 200)    
    5.  
    6.     For x =1 To 152
    7.         For y = 0 To 200
    8.             PSet (x, y), bArray(x,y)
    9.  
    10.         Next y
    11.     Next
    Depends on what type of data is stored in the array
    Like 0 = white color or 1= black for instance.
    You can put an if statement in the loop to choose what color you want.
    Semi VB Decompiler 0.07 Getting better everyday
    http://www.visualbasiczone.com/produ...ivbdecompiler/
    VisualBasicZone
    http://www.visualbasiczone.com
    EasyPHPBB.com
    Free PHPBB forums the quick and easy way!

  3. #3
    Android OpenGL ES Guru Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,250
    bArray(x,y) needs values. Otherwise it'll be all 0's. Loading a 256 color pic into memory and extracting it's bytes should do it.

  4. #4
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Well using PSet will be rather slow so I recommend using this method: (BTW I'm assuming its a grey scale image)
    VB Code:
    1. Private Type SAFEARRAYBOUND
    2.     cElements As Long
    3.     lLbound As Long
    4. End Type
    5.  
    6. Private Type SAFEARRAY2D
    7.     cDims As Integer
    8.     fFeatures As Integer
    9.     cbElements As Long
    10.     cLocks As Long
    11.     pvData As Long
    12.     Bounds(0 To 1) As SAFEARRAYBOUND
    13. End Type
    14.  
    15. Private Type BITMAP
    16.     bmType As Long
    17.     bmWidth As Long
    18.     bmHeight As Long
    19.     bmWidthBytes As Long
    20.     bmPlanes As Integer
    21.     bmBitsPixel As Integer
    22.     bmBits As Long
    23. End Type
    24.  
    25.  
    26. Dim i As Integer
    27. Dim j As Integer
    28. Dim pic() As Byte
    29. Dim sa As SAFEARRAY2D
    30. Dim bmp As BITMAP
    31.  
    32.     GetObjectAPI pic1.picture, Len(bmp), bmp
    33.  
    34.     With sa
    35.         .cbElements = 1
    36.         .cDims = 2
    37.         .Bounds(0).lLbound = 0
    38.         .Bounds(0).cElements = bmp.bmHeight
    39.         .Bounds(1).lLbound = 0
    40.         .Bounds(1).cElements = bmp.bmWidthBytes
    41.         .pvData = bmp.bmBits 'This is a pointer to where the BMP is in memory
    42.     End With
    43.  
    44.     CopyMemory ByVal VarPtrArray(pic), VarPtr(sa), 4
    45.  
    46.     For i = 0 To (bmp.bmWidth * 3) - 1 Step 3
    47.         For j = 0 To bmp.bmHeight - 1
    48.             pic(i, j) = SrcArray((152 - i), 200 - j)
    49.             pic(i + 1, j) = SrcArray((152 - i), 200 - j)
    50.             pic(i + 2, j) = SrcArray((152 - i), 200 - j)
    51.         Next
    52.     Next
    53.  
    54.     CopyMemory ByVal VarPtrArray(pic), 0&, 4
    55.  
    56.     pic1.Refresh




    If you want to convert it to a BMP file then check out my BMP File Format Example: http://www.electromanuk.com/Download.php?file_id=10
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    byte array one dimension or multidimension

    Thank you all for your posts,

    The byte array I have is a one dimension array, from 0 to 30400 bytes, this is because when I read the bytes I read them sequentially, do I need to change the array to be multidimensional? x and y? before using your code?

    Thank you in advance
    Peter

  6. #6
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Re: byte array one dimension or multidimension

    Posted by runtime
    Thank you all for your posts,

    The byte array I have is a one dimension array, from 0 to 30400 bytes, this is because when I read the bytes I read them sequentially, do I need to change the array to be multidimensional? x and y? before using your code?

    Thank you in advance
    Peter
    Give me a sec and I'll rewrite my code to fit that.....
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  7. #7
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    If you alter the loop to read like this:
    VB Code:
    1. For i = 0 To (bmp.bmWidth * 3) - 1 Step 3
    2.         For j = 0 To bmp.bmHeight - 1
    3.             pic(i, j) = SrcArray((200 - j) + ((152 - i) * 200))
    4.             pic(i + 1, j) = SrcArray((200 - j) + ((152 - i) * 200))
    5.             pic(i + 2, j) = SrcArray((200 - j) + ((152 - i) * 200))
    6.         Next
    7.     Next
    That should work let me know if it doesn't though.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    GetObjectAPI?

    Hello Electroman,

    Sorry to bother you again, what is GetObjectAPI in your code?


    Thanks

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    Nevermind, I found it in another of your posts

    I'll let you know how it works...

    Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long

    Thank you

  10. #10
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Ow sorry yea I forgot about the APIs, heres a couple others I used there:
    VB Code:
    1. Private Declare Function VarPtrArray Lib "msvbvm50.dll" Alias "VarPtr" (Ptr() As Any) As Long
    2. Private Declare Function VarPtr Lib "msvbvm50.dll" (Ptr As Any) As Long
    3. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    Unhappy didn't work

    Hi Electroman,

    I must be doing something wrong, it does not show the image...

    In your code: "pic1.Picture" I suppose is the picture box control where the image will be displayed, right?

    I did a trace on the program and found that bmp.bmWidth is 0, so it never enters the i,j loop...

    any ideas?

    Thank you

  12. #12
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Ow yea you'll need to load something into the picture box first, just a blank image the same size as the final one will be. I'd taken this froma sample I have but forgot in the sample it already loaded an image and manipulates it, instead of this one is actually creating the image .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    Unhappy subscript out of range...

    I get a "subscript out of range" here:

    pic(i, j) = pData((200 - j) + ((152 - i) * 200))

    my byte array pData goes from 0 to 30399 bytes, the image has 152 columns (x) and 200 rows (y)...

    What is being done in the i,j loops? maybe if I understand what is done I will not bother you again...

    Thank you

  14. #14
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    What were the numbers when the error happened? You have to make sure the image you use is 152x200 because otherwise it will run out of data.

    The loop is going through the image which pic() is linked to. it goes like this:

    pic(i, j) = Blue value for pixel (i,j)
    pic(i + 1, j) = Green value for pixel (i,j)
    pic(i + 2, j) = Red value for pixel (i,j)

    (0,0) is the bottom left which is why I had to add all that weird stuff to try and compenstae for (0) being the top left on your array.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  15. #15
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    I think it should be
    VB Code:
    1. pic(i, j) = pData((200 - j) + (i * 200))
    I was inverting x too so i was making 0,0 top right. mind I don't think this will have fixed the out of range error.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  16. #16
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    You might also find it useful to check out two of my samples on my examples page: http://www.electromanuk.com/Examples.php
    The 2nd & 3rd samples use this method to Invert an image or Alpha blend images together.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    Talking making progress...

    Wow, I can see something in the picture box but it is distorted and I still get the out of range error...

    bmp.bmWidth is 152 before entering the loops, so the i loop will go from 0 to 455

    pic(i, j) = pData((200 - j) + (i * 200)) is out of range when i = 153 and j = 0, this will give me pData(30800)...


    VB Code:
    1. For i = 0 To (bmp.bmWidth * 3) - 1 Step 3
    2.        For j = 0 To bmp.bmHeight - 1
    3.           pic(i, j) = pData((200 - j) + (i * 200))
    4.           pic(i + 1, j) = pData((200 - j) + (i * 200))
    5.           pic(i + 1, j) = pData((200 - j) + (i * 200))
    6.        Next
    7.     Next

    would it be better if I modify my code to read the byte array in 2 dimensions and use the first code you sent me?
    Last edited by Electroman; Nov 25th, 2004 at 12:33 PM.

  18. #18
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    We also have to divide i by 3 when used in your data array....this is because the pic array has three colour channels yet your array only has one.
    VB Code:
    1. For i = 0 To (bmp.bmWidth * 3) - 1 Step 3
    2.         For j = 0 To bmp.bmHeight - 1
    3.             pic(i, j) = SrcArray((200 - j) + ((152 - (i / 3)) * 200))
    4.             pic(i + 1, j) = SrcArray((200 - j) + ((152 - (i / 3)) * 200))
    5.             pic(i + 2, j) = SrcArray((200 - j) + ((152 - (i / 3)) * 200))
    6.         Next
    7.     Next
    The division shouldn't cause any rounding errors because i goes though values: 0, 3, 6, 9 so they will all divide by 3 fully .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    Unhappy out of range

    When i = 0, j = 0

    pic(i, j) = pData((200 - j) + ((152 - (i / 3)) * 200)) will give me:

    pic(0,0) = pData(200 + 30400) = out of range error...

    VB Code:
    1. For i = 0 To (bmp.bmWidth * 3) - 1 Step 3
    2.         For j = 0 To bmp.bmHeight - 1
    3.             pic(i, j) = pData((200 - j) + ((152 - (i / 3)) * 200))
    4.             pic(i + 1, j) = pData((200 - j) + ((152 - (i / 3)) * 200))
    5.             pic(i + 2, j) = pData((200 - j) + ((152 - (i / 3)) * 200))
    6.         Next
    7.     Next

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    different loop?

    Hi Electoman,

    is it ok to use this loop?

    VB Code:
    1. For y = 0 To 199
    2.        For x = 0 To 151
    3.           pic(x, y) = pData(y * 152 + x)
    4.        Next x
    5.     Next y

    Regards

  21. #21
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Re: out of range

    I think this should do it then:
    VB Code:
    1. For i = 0 To (bmp.bmWidth * 3) - 1 Step 3
    2.         For j = 0 To bmp.bmHeight - 1
    3.             pic(i, j) = pData((199 - j) + ((151 - (i / 3)) * 200))
    4.             pic(i + 1, j) = pData((199 - j) + ((151 - (i / 3)) * 200))
    5.             pic(i + 2, j) = pData((199 - j) + ((151 - (i / 3)) * 200))
    6.         Next
    7.     Next
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  22. #22

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    Talking no error, image is distorted

    Electroman,

    well, no out of range error, the image is displayed but distorted...
    Attached Images Attached Images  

  23. #23
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Could you post the project and I'll see what i can do .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  24. #24

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    file...

    Ok, I've written my byte array to disk using this code:

    VB Code:
    1. OutputFile386 = AppPath & "\Raw\Fingerprint.raw"
    2.    If Dir(OutputFile386) <> "" Then
    3.       Kill OutputFile386
    4.    End If
    5.    oFileNum = FreeFile
    6.    Open OutputFile386 For Binary Access Write As #oFileNum
    7.    'Write byte array into output file
    8.    Put #oFileNum, , pData()
    9.    Close #oFileNum

    the file is attached, someone told me that this file can be opened with Paint Shop Pro, the image should be a fingerprint. I just need to display the pData() array in a picture box...

    In the code above, pData() holds the image bytes (total of 30400)...
    Attached Files Attached Files

  25. #25
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Yea the file is fine, I opened it in PSP and the height and width were right:



    I'll try and see whats up with the code now.....
    Attached Images Attached Images  
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  26. #26
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Sorry for interrupting, here is some other code to check out in case it happens to work

    Please note this example only works with 8-bit (256 colors) images. You need to create a proper palette to see anything. I coded a quick greyscale palette function here to get you started, if you wish to try it out.

    VB Code:
    1. 'in a module
    2. Option Explicit
    3.  
    4. Public Const BI_RGB = 0&
    5. Public Const CBM_CREATEDIB = &H2
    6. Public Const CBM_INIT = &H4
    7. Public Const DIB_RGB_COLORS = 0
    8.  
    9. Public Type BITMAPINFOHEADER
    10.     biSize As Long
    11.     biWidth As Long
    12.     biHeight As Long
    13.     biPlanes As Integer
    14.     biBitCount As Integer
    15.     biCompression As Long
    16.     biSizeImage As Long
    17.     biXPelsPerMeter As Long
    18.     biYPelsPerMeter As Long
    19.     biClrUsed As Long
    20.     biClrImportant As Long
    21. End Type
    22.  
    23. Public Type RGBQUAD
    24.     rgbBlue As Byte
    25.     rgbGreen As Byte
    26.     rgbRed As Byte
    27.     rgbReserved As Byte
    28. End Type
    29.  
    30. Public Type BITMAPINFO_256
    31.     bmiHeader As BITMAPINFOHEADER
    32.     bmiColors(0 To 255) As RGBQUAD
    33. End Type
    34.  
    35. Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
    36. Public Declare Function CreateDIBitmap Lib "gdi32" (ByVal hDC As Long, lpInfoHeader As BITMAPINFOHEADER, ByVal dwUsage As Long, lpInitBits As Any, lpInitInfo As BITMAPINFO_256, ByVal wUsage As Long) As Long
    37. Public Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
    38. Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    39. Public Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
    40. Public Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
    41. Public Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
    42. Public Declare Function StretchBlt Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    43.  
    44. Public Sub GreyscalePalette(ByRef Palette() As Byte)
    45.     Dim A As Long, B As Long
    46.     For A = 0 To 255
    47.         B = A + A + A + A
    48.         Palette(B) = A
    49.         Palette(B + 1) = A
    50.         Palette(B + 2) = A
    51.         Palette(B + 3) = 0
    52.     Next A
    53. End Sub


    You need a picturebox with the following settings:
    AutoRedraw = True
    ScaleMode = vbPixels

    VB Code:
    1. 'in a form
    2. Private Sub Draw8bit(ByVal gWidth As Long, ByVal gHeight As Long, ByRef GraphicsData() As Byte)
    3.     Dim BMP_INFO As BITMAPINFO_256, BMP_DATA() As Byte, hDIB As Long
    4.     Dim Screen_hDC As Long, A As Long, B As Long
    5.     Dim Compat_DC As Long, MainPalette(1023) As Byte
    6.    
    7.     'On Error GoTo ErrorHandler
    8.  
    9.         If gWidth Mod 4 Then
    10.             'count new width
    11.             B = gWidth + 4 - gWidth Mod 4
    12.            
    13.             'resize graphics array
    14.             ReDim BMP_DATA(B * gHeight - 1)
    15.            
    16.             'copy graphics data row by row
    17.             For A = 0 To gHeight - 1
    18.                 RtlMoveMemory ByVal VarPtr(BMP_DATA(A * B)), ByVal VarPtr(GraphicsData(A * gWidth)), gWidth
    19.             Next A
    20.         Else
    21.             'resize graphics array
    22.             ReDim BMP_DATA(gWidth * gHeight - 1)
    23.            
    24.             'copy graphics data
    25.             RtlMoveMemory ByVal VarPtr(BMP_DATA(0)), ByVal VarPtr(GraphicsData(0)), gWidth * gHeight
    26.         End If
    27.  
    28.     'generate greyscale palette
    29.     GreyscalePalette MainPalette
    30.  
    31.     'copy palette data
    32.     RtlMoveMemory ByVal VarPtr(BMP_INFO.bmiColors(0)), ByVal VarPtr(MainPalette(0)), 1024
    33.    
    34.     'set DIB header
    35.     With BMP_INFO.bmiHeader
    36.         .biSize = Len(BMP_INFO.bmiHeader)
    37.         .biWidth = SpriteInfo(Index).Width      ' width in pixels
    38.         .biHeight = SpriteInfo(Index).Height    ' height in pixels
    39.         .biPlanes = 1                           ' 1 color plane
    40.         .biBitCount = 8                         ' 8 bits per pixel
    41.         .biCompression = BI_RGB                 ' no compression
    42.         .biSizeImage = 0                        ' unrequired with no compression
    43.         .biXPelsPerMeter = 0                    ' unrequired
    44.         .biYPelsPerMeter = 0                    ' unrequired
    45.         .biClrUsed = 256                        ' number colors in color table that are used by the image (0 means all)
    46.         .biClrImportant = 256                   ' number important colors (0 means all)
    47.     End With
    48.    
    49.     'get the screen's device context
    50.     Screen_hDC = GetDC(0)
    51.    
    52.     'create the DIB
    53.     hDIB = CreateDIBitmap(Screen_hDC, BMP_INFO.bmiHeader, CBM_INIT Or CBM_CREATEDIB, BMP_DATA(0), BMP_INFO, DIB_RGB_COLORS)
    54.    
    55.     'create a compatible device context
    56.     Compat_DC = CreateCompatibleDC(hDC)
    57.    
    58.     'select the DIB into the compatible DC
    59.     SelectObject Compat_DC, hDIB
    60.    
    61.     Picture1.BackColor = Picture1.BackColor
    62.    
    63.         'copy the compatible DC's image to the target
    64.         StretchBlt Picture1.hDC, (Picture1.ScaleHeight - gWidth) \ 2, (Picture1.ScaleHeight - gHeight) \ 2, gWidth, gHeight, Compat_DC, 0, gHeight - 1, gWidth, -gHeight, vbSrcCopy
    65.    
    66.     Picture1.Refresh
    67.    
    68. ErrorHandler:
    69.     'free up memory
    70.     ReleaseDC 0, Screen_hDC
    71.     DeleteDC Compat_DC
    72.     DeleteObject hDIB
    73.     Erase BMP_DATA
    74. End Sub


    Uhhuh... not tested, just a quick copypaste and then converting the code so that it should be usable as is... Just give it the byte array and the width and height information and it should work fine.

    Hope this helps (and works!)
    Last edited by Merri; Nov 25th, 2004 at 06:53 PM.

  27. #27
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    This loop works:
    VB Code:
    1. For j = bmp.bmHeight - 1 To 0 Step -1
    2.         For i = 0 To (bmp.bmWidth * 3) - 1 Step 3
    3.            
    4.             value = pData(tmp)
    5.            
    6.             pic(i, j) = value
    7.             pic(i + 1, j) = value
    8.             pic(i + 2, j) = value
    9.            
    10.             tmp = tmp + 1
    11.         Next
    12.     Next
    I found the problem was that you'd said the data goes in a columndirection whereas I found it doesn't it goes in a rowdirection . Rather than mess around with that formula I decided to just go with a int counting as we go so then I altered the for loops order and direction to fit it correctly .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  28. #28

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    Talking it works!

    Electroman,

    It worked fine , sorry about the columndirection issue, the docs for the device says so...

    Many, many, thanks

  29. #29

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    20

    white background?

    Hi Electroman,

    I was wondering how to display the image with a white background, I would like the fingerprint to be black and the background white? is there an easy way to do this?

    Thank you

  30. #30
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Re: white background?

    Posted by runtime
    Hi Electroman,

    I was wondering how to display the image with a white background, I would like the fingerprint to be black and the background white? is there an easy way to do this?

    Thank you
    Yea if you just invert the image....you can do this simply by changing:
    value = pData(tmp)
    To:
    value = 255 - pData(tmp)

    In the code I gave above or if your wanting to do this to any image then check out this sample on my site: http://www.electromanuk.com/Download.php?file_id=9


    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width