Solved

Image (or thumbnail) scaling / sizing / stretching

Posted on 2003-10-29
6
426 Views
Last Modified: 2013-11-22
Hello,

Can I do the following in VB6...

  At design-time, specify an area of a form, which is 500 x 500 pixels, which will be used to display an image
  At run-time, specify the image to be displayed in the area of the form (for example "d:\picture.JPG")
  If the selected images width <= 500 and height <= 500, then automatically display image at it's actual size
  If the selected images width > 500 or height > 500, then automatically resize image to fit 500 x 500, while retaining proportions

Which components should I be looking at?  (For example PictureBox or Image?)
Which properties / methods should I be looking at to determine the image's actual size?
Which properties / methods should I be looking at to resize image to fit 500 x 500?

*** Thank you for your time ***

Regards,
James
0
Comment
Question by:James20000
  • 4
6 Comments
 

Expert Comment

by:marcomania
ID: 9645151
I don't have a exact solution for you, but try the following

take both a image-box and a picture box (what of both has an auto resize option)

load the picture in the box - without out-resize
take the picture width and height
if its larger than you want, load it to the box with auto-resize and then back to the original box which is visible for the user.






0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9645757
From where do you load the image?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9645794
Sorry:
Did you try with me.paintpicture method?
I haven't VB installed to test it but i think (in a rush)
me.scalemode=vbpixels
me.paintpicture loadpicture(""d:\picture.JPG"),0 ,0,500,500

should do it...
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 2

Expert Comment

by:Djinn_ro
ID: 9646240
read the file format for bmp, jpg, gif, tiff, etc.
In the HEADER of these file is located dimension of picture (width and height)
try www.wotsit.org
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
ID: 9650229
Try with this:

Private Sub Form_Click()
Dim pic As StdPicture, H As Integer, W As Integer, frmW As Integer, frmH As Integer
' replace with correct path and filename
Set pic = LoadPicture("n:\credicop.jpg")
With pic
    H = Int(Me.ScaleX(pic.Height, vbHimetric, vbPixels))
    W = Int(Me.ScaleY(pic.Width, vbHimetric, vbPixels))
    frmW = Me.ScaleWidth
    frmH = Me.ScaleHeight
End With
If frmW > W Or frmH > H Then
    Me.PaintPicture pic, 0, 0, W, H, , , , , vbSrcCopy
Else
    Me.PaintPicture pic, 0, 0, frmW, frmH, , , , , vbSrcCopy
End If
End Sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9652565
That' was just an example, i think you need to use a select case statement to manage the various scenarios.
Cheers
Thanks for "A" grade.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question