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 2809
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(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?
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 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...
|
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...
|
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
|
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...
|
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...
| |
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...
|
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...
|
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 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...
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
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
| | |