Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Drawing DIBs (VB6 - Access XP)

    I need to display DIBs (Device Independent Bitmaps) on an Access form, the sample code I have uses -
    Public Declare Function DrawDibDraw Lib "Msvfw32" (ByVal hdd As Long, ByVal hDC As Long, ByVal xDst As Long, ByVal yDst As Long, ByVal dxDst As Long, ByVal dyDst As Long, lpbi As BITMAPINFOHEADER, lpBits As Any, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dxSrc As Long, ByVal dySrc As Long, ByVal wFlags As Long) As Long

    which is called using -
    TempResult = DrawDibDraw(hDibOpen, Picture1.hDC, 0, 0, xSize, ySize, BInfoHeader, ByVal pMem, 0, 0, BInfoHeader.biWidth, BInfoHeader.biHeight, 0)
    This line doesn't work in Access - I'm trying to use an image control but unlike VB6 it does not have the hDC property and I suspect the same drawing ability.
    Does nayone know how to draw a DIB in an Access Image control?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Drawing DIBs (VB6 - Access XP)

    Can you explain why you want to do it this way? The Access Image control can display .dib files, all you have to do is to set the Picture property to the path and name of the .dib file

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Drawing DIBs (VB6 - Access XP)

    That would just be so easy so I guess I must be doing something else wrong.
    When I write the BLOB out to a file I get the message "Error No 2114 TIMI doesn't support the format of the file 'C"Temp.dib,' or file is too large, Try converting the file to a BMP or GIF format.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Drawing DIBs (VB6 - Access XP)

    Where does your image come from? Have you tried saving as a .bmp? (The Windows .bmp format is a dib too).

  5. #5
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Drawing DIBs (VB6 - Access XP)

    This is the code that is being used to write the BMP as a DIB into a BLOB
    FileDialog.ShowOpen
    ' Open the file and read it
    hSizeIn = FileLen(FileDialog.FileName)
    f = FreeFile
    ReDim ByteArray(hSizeIn)
    Open FileDialog.FileName For Binary As #f
    Get #f, 1, ByteArray
    Close f
    'Copy the memory inside the Gobal memory
    hMemIn = GlobalAlloc(GMEM_SHARE, hSizeIn)
    pMem = GlobalLock(hMemIn)
    ' To get a DIB we just discard the first 14 bytes of the BMP file
    CopyMemory ByVal pMem, ByteArray(14), hSizeIn - 14

    'Use the N5GetDasedDib Function to pack the Blob
    ' Public Declare Function N5GetDasedDib Lib "N5DaseV2" Alias "_N5GetDasedDib@8" (ByVal hDib As Long, ByVal bCompress As Boolean) As Long
    hMemOut = N5GetDasedDib(hMemIn, False)
    GlobalUnlock hMemIn
    GlobalFree hMemIn
    If hMemOut <> 0 Then
    hSizeOut = GlobalSize(hMemOut)
    pMem = GlobalLock(hMemOut)
    ReDim ByteArray(hSizeOut)
    CopyMemory ByteArray(0), ByVal pMem, hSizeOut
    GlobalFree hMemOut

    ' Copy the contents of the file to the field
    Set Field = Adodc1.Recordset.Fields.Item("PhotoField")
    Field = ByteArray()

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Drawing DIBs (VB6 - Access XP)

    But what is the purpose? You're starting with a .bmp, so you can skip all this code and set the Picture property of the Image control to the path and name of the .bmp file.

  7. #7
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Drawing DIBs (VB6 - Access XP)

    I have tried writing it out from the BLOB with a BMP extention as well and get the same error - I replied to my previous post with the code that I am told is being used to write it into the SQL database. I can write BMPs and JPGs in as BLOBs and write them out again successfully so it's not the BLOB that is the problem, it must be the file that is being written in.

    So a DIB and a BMP are the same thing - form what I have gathered so far the first first 14 bytes are stripped off the BMP to make it a DIB. is this right? if so are they still interchangeable?

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Drawing DIBs (VB6 - Access XP)

    Please see my reply <post:=663,123>post 663,123</post:> - I don't understand why you would want to read a .bmp file into a blob then somehow store the blob into an Image control if you can store or link the .bmp directly in the Image control.

  9. #9
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Drawing DIBs (VB6 - Access XP)

    The file is written into a SQL Server database field as a BLOB by another organisation, the database is then sent to another another organisation at another location where I have to write it out and display it on an Access form.

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Drawing DIBs (VB6 - Access XP)

    If you write out the blob field to a file (.bmp or .dib), can you open the file successfully by double-clicking it in Windows Explorer?

  11. #11
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Drawing DIBs (VB6 - Access XP)

    No it won't view. and Paint tells me it is not a valid bitmap (that's opening the file with a BMP extention or the same file with a DIB extention.
    The JPGs and BMPs I write in myself and then out again open OK but not the file written from the records sent to me.

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Drawing DIBs (VB6 - Access XP)

    You wrote

    > The file is written into a SQL Server database field as a BLOB by another organisation

    The problem would seem to be there. The other organisation will have to get its act together before you can do anything.

  13. #13
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Drawing DIBs (VB6 - Access XP)

    Thanks for ALL of that, I have asked them to supply a sample of a DIB so that I can test with it to see if a) i can open it, [img]/forums/images/smilies/cool.gif[/img] that it will view in an image control and c) I can write it in and out of BLOBs successfully. They can view the image with the application that is used to enter it and the VB6 code sample is supposed to be the method used, but as the VB6 sample they sent me is not complete and will not run without errors I really am not sure where the problem lies. So thankyou for all your input The whole thing was looking harder than I guess it should be So it was good to get your input, I was getting totally lost.

  14. #14
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Drawing DIBs (VB6 - Access XP)

    Hi Hans,
    So far I haven't been able to get my hands on a DIB file to test with, but I have got the VB6 ap displaying the images -
    Set Field = Adodc1.Recordset.Fields.Item("Student_Photo")
    If IsNull(Field.Value) = False Then
    ByteArray() = Field.Value
    hSizeIn = Field.ActualSize
    'Copy the memory inside the Gobal memory
    hMemIn = GlobalAlloc(GMEM_SHARE, hSizeIn)
    pMem = GlobalLock(hMemIn)
    CopyMemory ByVal pMem, ByteArray(0), hSizeIn
    GlobalUnlock hMemIn
    'Use the N5GetDibFunction to unpack the Blob
    hMemOut = N5GetDib(hMemIn)
    GlobalFree hMemIn
    If hMemOut <> 0 Then
    hSizeOut = GlobalSize(hMemOut)
    pMem = GlobalLock(hMemOut)
    ReDim ByteArray(hSizeOut)
    CopyMemory ByteArray(0), ByVal pMem, hSizeOut
    CopyMemory BInfoHeader, ByteArray(0), Len(BInfoHeader)
    StartDib = Len(BInfoHeader) + PaleteSize(BInfoHeader)
    CopyMemory ByVal pMem, ByteArray(StartDib), hSizeOut - StartDib
    hDibOpen = DrawDibOpen()
    xSize = (Picture1.Width / Screen.TwipsPerPixelX)
    ySize = (Picture1.Height / Screen.TwipsPerPixelX)
    If (hDibOpen <> 0) And (hDibOpen <> -1) Then
    TempResult = DrawDibDraw(hDibOpen, Picture1.hDC, 0, 0, xSize, ySize, BInfoHeader, ByVal pMem, 0, 0, BInfoHeader.biWidth, BInfoHeader.biHeight, 0)
    If TempResult = 0 Then
    MsgBox "Error Drawing DIB"
    End If
    End If
    I am now having trouble making this work in Access. If I can get the DrawDibDraw function to work then problem solved. I can just use the value - 15 for the TwipsperPixel but I cannot find an equivalent of the picture.hDC. I know that is some sort of handle but how would this translate to Access? The value, when I run it in VB, is -1862196618

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Drawing DIBs (VB6 - Access XP)

    This is way over my head. I don't have the slightest idea how to make this work in Access, sorry.

Page 1 of 2 12 LastLast

Posting Permissions

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