473,769 Members | 3,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Picture controls, Access Image controls, DIBS and BLOBs

11 New Member
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 2809
fplesco
82 New Member
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
kentgorrell
11 New Member
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(hDi bOpen, Picture1.hDC, 0, 0, xSize, ySize, BInfoHeader, ByVal pMem, 0, 0, BInfoHeader.biW idth, BInfoHeader.biH eight, 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
13879
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 used by people categorizing thousands of images. The problem I have is that both the picture control, and the image control seem unable to open certain jpg images for an unknown reason. The error message simply states "Invalid Picture". I can...
10
9509
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 draw (but for specific uses). What I need to be able to do is import graphics and text and then move them around the background until they are where I want them and then export it out as an image file. The problem is that I need to be able to...
1
2377
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. Can anyone help me how to do this Thanks in advance PS
1
4920
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 images, jpg images) to Microsoft SQL Server 2000 using Microsoft DTS. On trying to perform this simple conversion I recieved the error "Need to run the object to perform the operation - Exception Access Violation" from Microsoft DTS and my table...
48
11925
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 have 500000 records around. Somebody said the best way to do that was encoder the picture to field bytea but I dont know about this. Another way is save the path to the picture file but I dont like so much because I need to write to disk by OS...
6
8191
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 fine. I then placed the fields in the report. Then I previewed the report. The picture resized or something and all of my nice fields were no longer in the same position. It didn't make any difference if I selected Crop, Zoom, or...
5
4874
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 the db too, again without touching metal. I need a way to overlay some text on the image but I'm stuck. All the help I find uses files in the filesystem, and when I try to convert the example to my imagestream model it fails and I can't...
2
3020
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
16361
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 have tried the MS kb 210486 and successfully got the import/export to work with a sample table, but only the first record. I do not wish to impost binary data to the database, it's already there. I simply wish to pick up the binary BLOB from the photo...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10048
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.