473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Picture controls, Access Image controls, DIBS and BLOBs

I had a wonderful time working out how to read and write BLOBs using GetChunk until I found the new streaming object in ADO 2.6 very easy.
Now I am confronted with DIBs
The code I have is VB6 but only partial so I can't actually run it. Anyhow I need to get it to work in Access but there are a couple of properties and methods of the picture control in VB6 that don't have corresponding ones in Access. Like TwipsPerPixel which I can just estimate at 15 but I have no idea what Picture.hDC is - can anyone tell me please.
Or if anyone has any working code for viewing DIBs that will work in VBA then that would be even better.
Jul 26 '07 #1
2 2792
fplesco
82
I had a wonderful time working out how to read and write BLOBs using GetChunk until I found the new streaming object in ADO 2.6 very easy.
Now I am confronted with DIBs
The code I have is VB6 but only partial so I can't actually run it. Anyhow I need to get it to work in Access but there are a couple of properties and methods of the picture control in VB6 that don't have corresponding ones in Access. Like TwipsPerPixel which I can just estimate at 15 but I have no idea what Picture.hDC is - can anyone tell me please.
Or if anyone has any working code for viewing DIBs that will work in VBA then that would be even better.
Hi kentgorrell -

Can you try this VBA code?

Make an MS Access table called "EmpTable" or any name you want
And make this fields

EmpID Text
FullName Text
EmpPicture OLE Object

Expand|Select|Wrap|Line Numbers
  1. Dim Con As Connection
  2. Dim Rs As Recordset
  3.  
  4. Private Sub cmdBrowse_Click()
  5.     txtPath = BrowsePicture
  6.         If txtPath <> "" Then
  7.         Image1.PictureSizeMode = fmPictureSizeModeStretch
  8.         Image1.Picture = LoadPicture("")
  9.         Image1.Picture = LoadPicture(txtPath)
  10.     Else
  11.         Image1.Picture = LoadPicture("")
  12.     End If
  13. End Sub
  14.  
  15. Public Function BrowsePicture() As String
  16. Dim FileLocation As String
  17.     Excel.Application.Dialogs.Application.FileDialog(msoFileDialogOpen).Title = "Select Employee Picture"
  18.     Excel.Application.Dialogs.Application.FileDialog(msoFileDialogOpen).Show
  19.     FileLocation = Excel.Application.Dialogs.Application.FileDialog(msoFileDialogOpen).InitialFileName
  20.  
  21.     FileLocation = Excel.Application.Dialogs.Application.FileDialog(msoFileDialogOpen).SelectedItems.Item(1)
  22.     'Set FS = CreateObject("Scripting.FileSystemObject")
  23.     'Set A = FS.OpenTextFile(FileLocation, 1, False) '"c:\COMFILE.txt"
  24.     If LCase(Right(FileLocation, 4)) <> ".jpg" And _
  25.        LCase(Right(FileLocation, 4)) <> ".bmp" And _
  26.        LCase(Right(FileLocation, 4)) <> ".gif" Then
  27.         MsgBox "Invalid picture selection.", vbCritical, "Saving BLOB"
  28.         Exit Function
  29.     End If
  30.     BrowsePicture = FileLocation
  31. End Function
  32.  
  33. Private Sub cmdSave_Click()
  34. If cmdSave.Caption = "New Record" Then
  35.     cmdSave.Caption = "Save Record"
  36.     txtPath.Enabled = True
  37.     ClearText
  38. Else
  39.     SavePic
  40.     txtPath.Enabled = False
  41.     ClearText
  42.     cmdSave.Caption = "New Record"
  43. End If
  44. End Sub
  45.  
  46. Public Sub ClearText()
  47.     txtFullname = ""
  48.     txtID = ""
  49. End Sub
  50. Private Sub cmdShow_Click()
  51. Dim ProvSSN As String
  52. Dim SavePath As String
  53. Dim PicEdit As Picture
  54. Dim strtmpFilename As String
  55. On Error GoTo ErrHandler
  56.     txtPath = ""
  57.     strtmpFilename = IIf(txtPath <> "", txtPath, "C:\tmpPic.jpg")
  58.     Set Con = New Connection
  59.     Con.Open "SavePicture"
  60.     Set Rs = New Recordset
  61.     Rs.ActiveConnection = Con
  62.     Rs.Open "Select * from EmpTable where EmpID = '" & txtID & "'", Con, adOpenKeyset, adLockOptimistic
  63.     If Rs.EOF Then
  64.         Image1.Picture = LoadPicture("")
  65.         Me.Caption = "Saving and Retrieving BLOB"
  66.         MsgBox "No record found.", vbInformation, "Saving BLOB"
  67.         Exit Sub
  68.     End If
  69.     Rs.MoveFirst
  70.     Me.Caption = Rs!FullName
  71.     txtFullname = Me.Caption
  72.     Image1.Picture = LoadPicture("")
  73.     Call BintoFile(strtmpFilename, Rs.Fields("EmpPicture"))
  74.     'If Rs.Fields("EmpPicture").Type = adLongVarBinary Then
  75.      Image1.Picture = LoadPicture(strtmpFilename)
  76.     'Else
  77.         'Me.Caption = "Saving and Retrieving BLOB"
  78.     'End If
  79.     Image1.PictureSizeMode = fmPictureSizeModeStretch
  80.     'Remove any existing destination file
  81.     If Len(Dir$(strtmpFilename)) > 0 Then
  82.        Kill strtmpFilename
  83.     End If
  84.     Exit Sub
  85. ErrHandler:
  86.     MsgBox Err.Description, vbCritical, "Saving BLOB"
  87. End Sub
  88.  
  89. Private Sub BintoFile(sFileName As String, fld As Field)
  90. Dim bBuffer() As Byte
  91. Dim ChunkSize As Long
  92. Dim Chunks As Long
  93. Dim Fl As Long
  94. Dim Fragment As Long
  95. Dim Chunk() As Byte
  96.  
  97.     'Recreate a new file
  98.     Open sFileName For Binary As #1
  99.     'Use a 32K initial chuck size
  100.     ChunkSize = 16384
  101.     Fl = fld.ActualSize
  102.     Chunks = Fl \ ChunkSize
  103.     Fragment = Fl Mod ChunkSize
  104.    ' Resize the byte array Chunk to the size of the fraction of a chunk calced above
  105.     ReDim Chunk(Fragment)
  106.    ' Get this fraction first and output it to the binary file
  107.     Chunk() = fld.GetChunk(Fragment)
  108.     Put #1, , Chunk()
  109.     For i = 1 To Chunks
  110.        ReDim Buffer(ChunkSize)
  111.        Chunk() = fld.GetChunk(ChunkSize)
  112.        Put #1, , Chunk()
  113.     Next i
  114.     Close #1
  115. End Sub
  116.  
  117. Public Function SavePic()
  118. Dim b() As Byte, f As Long, fn As String
  119. On Error GoTo ErrHandler
  120.     Set Con = New Connection
  121.     Con.Open "SavePicture"
  122.     f = FreeFile()
  123.     fn = txtPath
  124.     Open fn For Binary Access Read As #f
  125.     ReDim b(FileLen(fn) - 1)
  126.     Get #f, , b()
  127.     Set Rs = New Recordset
  128.     Set Rs.ActiveConnection = Con
  129.     Rs.Open "Select * from EmpTable", Con, adOpenDynamic, adLockOptimistic
  130.     Rs.AddNew
  131.     Rs("EmpID") = txtID
  132.     Rs("Fullname") = txtFullname
  133.     Rs("EmpPicture") = b()
  134.     Rs.Update
  135.     Close #f
  136.     txtPath = ""
  137.     MsgBox "Record has been saved.", vbInformation, "Saving BLOB"
  138.     Exit Function
  139. ErrHandler:
  140.     MsgBox Err.Description, vbCritical, "Saving BLOB"
  141. End Function
  142.  
  143. Private Sub txtPath_Change()
  144.  
  145. End Sub
  146.  
  147. Private Sub UserForm_Activate()
  148.     Me.Caption = "Saving and Retrieving BLOB"
  149. End Sub
  150.  
  151.  
Note: SavePicture is the name of my ODBC, if you want... replace it with a connection string.

I apologize if I can't give a detail on this but, i will attach, snapshots for a better understanding of this program and a bit of a clue.

Oh, sorry, can I insert images here? I think, there's no way for me to do that.

If you cant get the codes running, just give me your email and i will send you the snapshots.

Godspeed.
Jul 27 '07 #2
Thanks for that - it helped to clarify what was happening with the reading in and out of the BLOB using GetChunk but it didn't help with the DIB specific display, specifically this line -
DrawDibDraw(hDibOpen, Picture1.hDC, 0, 0, xSize, ySize, BInfoHeader, ByVal pMem, 0, 0, BInfoHeader.biWidth, BInfoHeader.biHeight, 0)
That uses the picture.hDC that is in VB6 but not in Access VBA
Do you know what this is, or if there is an Access equivalent?
Jul 28 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Trevor Fairchild | last post by:
I am making a program that categorizes pictures. The picture paths are stored in an Access Database, vb6 connects using adodc controls. This program works specifically with .jpg files. It will be...
10
by: Chris Coho, Jr. | last post by:
Ok, I'll explain the whole problem because there may be several ways to solve this and hopefully someone knows one. What I'm doing is creating a specialty template editor, similar to say a corel...
1
by: PS | last post by:
I want to extract an image from sqlserver 2000 table and display it in picture box in vb.net form using ado.net and vb.net The image in the sql server 2000 table is stored in 'image' datatype. ...
1
by: gary.scott | last post by:
Aaaaaarrgghh ! (that's better) I am trying to convert a field within my Oracle 9i Database that is of type BLOB (but this BLOB may contain a combination of clobs/varchars or images such as gif...
48
by: Edwin Quijada | last post by:
Hi !! Everybody I am developing app using Delphi and I have a question: I have to save pictures into my database. Each picture has 20 o 30k aprox. What is the way more optimus? That 's table will...
6
by: Salad | last post by:
Hi: I have a Bill of Lading template from the printer that I saved as a BMP. I created a new report and in the report's picture property told it the BMP file name. It brought the image in just...
5
by: Brian Lowe | last post by:
My web site accepts uploaded photos and stores them in a SQL table as BLObs so they never touch the filesystem. I have a way to create a thumbnail version of the uploaded image and store that in...
2
by: Igor | last post by:
Can i put picture in sql server database but not filename and path. I want to put complete picture in field in database. Is it possible?
5
by: bhodgins | last post by:
Hi, I am new on here, and had a newbie question that I am stumped with. I am not new to access, but am new to VB. I am trying to export BLOBs from a field called photo to external jpeg files. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.