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.
2 2792
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 -
Dim Con As Connection
-
Dim Rs As Recordset
-
-
Private Sub cmdBrowse_Click()
-
txtPath = BrowsePicture
-
If txtPath <> "" Then
-
Image1.PictureSizeMode = fmPictureSizeModeStretch
-
Image1.Picture = LoadPicture("")
-
Image1.Picture = LoadPicture(txtPath)
-
Else
-
Image1.Picture = LoadPicture("")
-
End If
-
End Sub
-
-
Public Function BrowsePicture() As String
-
Dim FileLocation As String
-
Excel.Application.Dialogs.Application.FileDialog(msoFileDialogOpen).Title = "Select Employee Picture"
-
Excel.Application.Dialogs.Application.FileDialog(msoFileDialogOpen).Show
-
FileLocation = Excel.Application.Dialogs.Application.FileDialog(msoFileDialogOpen).InitialFileName
-
-
FileLocation = Excel.Application.Dialogs.Application.FileDialog(msoFileDialogOpen).SelectedItems.Item(1)
-
'Set FS = CreateObject("Scripting.FileSystemObject")
-
'Set A = FS.OpenTextFile(FileLocation, 1, False) '"c:\COMFILE.txt"
-
If LCase(Right(FileLocation, 4)) <> ".jpg" And _
-
LCase(Right(FileLocation, 4)) <> ".bmp" And _
-
LCase(Right(FileLocation, 4)) <> ".gif" Then
-
MsgBox "Invalid picture selection.", vbCritical, "Saving BLOB"
-
Exit Function
-
End If
-
BrowsePicture = FileLocation
-
End Function
-
-
Private Sub cmdSave_Click()
-
If cmdSave.Caption = "New Record" Then
-
cmdSave.Caption = "Save Record"
-
txtPath.Enabled = True
-
ClearText
-
Else
-
SavePic
-
txtPath.Enabled = False
-
ClearText
-
cmdSave.Caption = "New Record"
-
End If
-
End Sub
-
-
Public Sub ClearText()
-
txtFullname = ""
-
txtID = ""
-
End Sub
-
Private Sub cmdShow_Click()
-
Dim ProvSSN As String
-
Dim SavePath As String
-
Dim PicEdit As Picture
-
Dim strtmpFilename As String
-
On Error GoTo ErrHandler
-
txtPath = ""
-
strtmpFilename = IIf(txtPath <> "", txtPath, "C:\tmpPic.jpg")
-
Set Con = New Connection
-
Con.Open "SavePicture"
-
Set Rs = New Recordset
-
Rs.ActiveConnection = Con
-
Rs.Open "Select * from EmpTable where EmpID = '" & txtID & "'", Con, adOpenKeyset, adLockOptimistic
-
If Rs.EOF Then
-
Image1.Picture = LoadPicture("")
-
Me.Caption = "Saving and Retrieving BLOB"
-
MsgBox "No record found.", vbInformation, "Saving BLOB"
-
Exit Sub
-
End If
-
Rs.MoveFirst
-
Me.Caption = Rs!FullName
-
txtFullname = Me.Caption
-
Image1.Picture = LoadPicture("")
-
Call BintoFile(strtmpFilename, Rs.Fields("EmpPicture"))
-
'If Rs.Fields("EmpPicture").Type = adLongVarBinary Then
-
Image1.Picture = LoadPicture(strtmpFilename)
-
'Else
-
'Me.Caption = "Saving and Retrieving BLOB"
-
'End If
-
Image1.PictureSizeMode = fmPictureSizeModeStretch
-
'Remove any existing destination file
-
If Len(Dir$(strtmpFilename)) > 0 Then
-
Kill strtmpFilename
-
End If
-
Exit Sub
-
ErrHandler:
-
MsgBox Err.Description, vbCritical, "Saving BLOB"
-
End Sub
-
-
Private Sub BintoFile(sFileName As String, fld As Field)
-
Dim bBuffer() As Byte
-
Dim ChunkSize As Long
-
Dim Chunks As Long
-
Dim Fl As Long
-
Dim Fragment As Long
-
Dim Chunk() As Byte
-
-
'Recreate a new file
-
Open sFileName For Binary As #1
-
'Use a 32K initial chuck size
-
ChunkSize = 16384
-
Fl = fld.ActualSize
-
Chunks = Fl \ ChunkSize
-
Fragment = Fl Mod ChunkSize
-
' Resize the byte array Chunk to the size of the fraction of a chunk calced above
-
ReDim Chunk(Fragment)
-
' Get this fraction first and output it to the binary file
-
Chunk() = fld.GetChunk(Fragment)
-
Put #1, , Chunk()
-
For i = 1 To Chunks
-
ReDim Buffer(ChunkSize)
-
Chunk() = fld.GetChunk(ChunkSize)
-
Put #1, , Chunk()
-
Next i
-
Close #1
-
End Sub
-
-
Public Function SavePic()
-
Dim b() As Byte, f As Long, fn As String
-
On Error GoTo ErrHandler
-
Set Con = New Connection
-
Con.Open "SavePicture"
-
f = FreeFile()
-
fn = txtPath
-
Open fn For Binary Access Read As #f
-
ReDim b(FileLen(fn) - 1)
-
Get #f, , b()
-
Set Rs = New Recordset
-
Set Rs.ActiveConnection = Con
-
Rs.Open "Select * from EmpTable", Con, adOpenDynamic, adLockOptimistic
-
Rs.AddNew
-
Rs("EmpID") = txtID
-
Rs("Fullname") = txtFullname
-
Rs("EmpPicture") = b()
-
Rs.Update
-
Close #f
-
txtPath = ""
-
MsgBox "Record has been saved.", vbInformation, "Saving BLOB"
-
Exit Function
-
ErrHandler:
-
MsgBox Err.Description, vbCritical, "Saving BLOB"
-
End Function
-
-
Private Sub txtPath_Change()
-
-
End Sub
-
-
Private Sub UserForm_Activate()
-
Me.Caption = "Saving and Retrieving BLOB"
-
End Sub
-
-
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.
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
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?
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
| | |