Link to home
Start Free TrialLog in
Avatar of hrolsons
hrolsonsFlag for United States of America

asked on

Resize .jpg in VB6

I am trying, using VB6, to resize and save a .jpg with the largest side being 150px.

It has been so long since I've used VB6 that I'm having trouble figuring out how to start?

I think I used to do this using a command line and Imagemagick.
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Windows Image Acquisition Library 2.0 is your "friend"
Check this code
Public Function CreateThumbnail(inPath As String) As Variant
'ok a fully qualified path is passed in.
'lets resize this puppy and put it into the small folder
'you can clean up TempImages after

Dim img As WIA.ImageFile
Dim IP As ImageProcess

Set img = CreateObject("WIA.ImageFile")
Set IP = CreateObject("WIA.ImageProcess")
IP.Filters.Add IP.FilterInfos("Scale").FilterID
img.LoadFile inPath

IP.Filters(1).Properties("MaximumWidth") = 160
IP.Filters(1).Properties("MaximumHeight") = img.Height / img.Width * 160

Set img = IP.Apply(img)
CreateThumbnail = img.FileData.BinaryData

End Function

Open in new window

I use it like this
rsImages.Fields("thumbnail") = CreateThumbnail(.SelectedItems(1))

Open in new window

Avatar of hrolsons


So I used your function like this:

x = CreateThumbnail("c:\temp\temp.jpg")

It ran, but I can't find the thumbnail it created.
Put a breakpoint to see what you might missing...did you forgot to reference the library ?
Yes, I included the reference.  The code all runs without error, it's just I don't know where the thumbnail is.
Just put a breakpoint on the
CreateThumbnail = img.FileData.BinaryData

Open in new window

Essentially the whole process takes place in memory my code it is stored to recordset...if you want to output it to a file you have to use ADODB stream.
It seems to be putting it into the recordset. rsImages. What do you do with that recordset?
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you so much!!!