Option Compare Database
Option Explicit
'reference to Microsoft Windows Image Acquisition Library 2.0 is required
'***use the code as desired
'***please maintain a reference to Nick67 of Experts Exchange as the author
Private Sub ShrinkEm(thePictureID As Long)
Dim s As String
Dim BuiltPath As String
Dim TempPath As String
Dim x As Integer
Dim Img As WIA.ImageFile
Dim myfolder As Object
Dim myfile As Object
Dim DesiredDPI As Integer
Dim IP As ImageProcess
Set IP = CreateObject("WIA.ImageProcess")
Dim fs As Object 'our friend the filesystemobject
Set fs = CreateObject("Scripting.FileSystemObject")
IP.Filters.Add IP.FilterInfos("Scale").FilterID
'IP.Filters(1).Properties("MaximumWidth") = 1600 'you can hand code an exact size
'IP.Filters(1).Properties("MaximumHeight") = 1200 'you can hand code an exact size
'variables for a recordset in tblPictures which stores the path to the images
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM [tblPictures] WHERE PictureID = " & thePictureID, dbOpenDynaset, dbSeeChanges)
BuiltPath = rs!Path 'where the original is
TempPath = CurrentProject.Path & "\Resized\" ' a place to store dynamically generated images
'clean out resized folder
Set myfolder = fs.getfolder(TempPath)
For Each myfile In myfolder.files
fs.DeleteFile myfile.Path, True 'whack the file, force it to die
Next myfile
DesiredDPI = Nz(Forms!form1!txtDesiredDPI, 96) ' from the form
For x = 1 To 3 'resize and point the three controls at the resized image
Set Img = CreateObject("WIA.ImageFile")
Img.LoadFile (BuiltPath) 'load the stored jpg in WIA
IP.Filters(1).Properties("MaximumWidth") = Me.Controls("Image" & x).Width * DesiredDPI / 1440 '96 dpi * control width / twips per inch
IP.Filters(1).Properties("MaximumHeight") = Me.Controls("Image" & x).Height * DesiredDPI / 1440 '96 dpi * control height /t wips per inch
Set Img = IP.Apply(Img)
s = TempPath & x & ".jpg"
Img.SaveFile (s)
Me.Controls("Image" & x).Picture = s
Set Img = Nothing
Next x
End Sub
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
ShrinkEm (Me.PictureID)
End Sub
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (2)
Commented:
Commented: