Resize .jpg in VB6

hrolsons
hrolsons used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
John TsioumprisSoftware & Systems Engineer

Commented:
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

Author

Commented:
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 TsioumprisSoftware & Systems Engineer

Commented:
Put a breakpoint to see what you might missing...did you forgot to reference the library ?
Clipboard01.jpg
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Yes, I included the reference.  The code all runs without error, it's just I don't know where the thumbnail is.
John TsioumprisSoftware & Systems Engineer

Commented:
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 LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
It seems to be putting it into the recordset. rsImages. What do you do with that recordset?
Software & Systems Engineer
Commented:
Check this code
Public Function CreateThumbnail(inPath As String)
Dim stream As New ADODB.stream
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)


stream.Open
stream.Type = adTypeBinary
stream.Write img.FileData.BinaryData
stream.SaveToFile "D:\Share\small.jpg", adSaveCreateNotExist
stream.Close
End Function

Open in new window

I had to recreate it from scratch ...i really need to restore my old work.... :)

Author

Commented:
Thank you so much!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial