Avatar of hrolsons
hrolsons
Flag 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.
Visual Basic Classic

Avatar of undefined
Last Comment
hrolsons

8/22/2022 - Mon
John Tsioumpris

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

hrolsons

ASKER
So I used your function like this:

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

It ran, but I can't find the thumbnail it created.
John Tsioumpris

Put a breakpoint to see what you might missing...did you forgot to reference the library ?
Clipboard01.jpg
Your help has saved me hundreds of hours of internet surfing.
fblack61
hrolsons

ASKER
Yes, I included the reference.  The code all runs without error, it's just I don't know where the thumbnail is.
John Tsioumpris

Just put a breakpoint on the
CreateThumbnail = img.FileData.BinaryData

Open in new window

Essentially the whole process takes place in memory ....in my code it is stored to recordset...if you want to output it to a file you have to use ADODB stream.
Martin Liss

It seems to be putting it into the recordset. rsImages. What do you do with that recordset?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
John Tsioumpris

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
hrolsons

ASKER
Thank you so much!!!