We help IT Professionals succeed at work.

Resize .jpg in VB6

hrolsons
hrolsons asked
on
126 Views
Last Modified: 2019-03-17
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

John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

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
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Put a breakpoint to see what you might missing...did you forgot to reference the library ?
Clipboard01.jpg

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
CERTIFIED EXPERT
Distinguished Expert 2019

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 LissSocial distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
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
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you so much!!!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.