Link to home
Start Free TrialLog in
Avatar of BeauT
BeauT

asked on

Displaying thumbnails

I am looking for either an algorithm or free control or other means by witch to display thumbnails.  I tried using the normal image control and setting the Stretch property to true and sizing the image control to thumbnail size.  However this results usually in a distorted picture since most pictures do not have the same exact proportion as the dimensions of my image control.  In other words, if the image control is 1200 by 1200, then the image would have to have the same size height and width to not be distorted. Ideally I'd like an algorithm, but any good solution will work.
Avatar of jbil
jbil

Could use invisible picturebox with autosize true to get size and set image1 width and height to a percent of that.


Private Sub Command1_Click()
thumb Image1, Picture1, "D:\Webpage\big.jpg"
End Sub

Private Sub thumb(des As Object, source As Object, sPicname As String)
Set source.Picture = LoadPicture(sPicname)

des.Width = source.Width * 0.25
des.Height = source.Height * 0.25
'could optionly change percent with select case depending on size
des.Picture = source.Picture

End Sub


Private Sub Form_Load()
Picture1.Visible = False
Picture1.AutoSize = True
Image1.Stretch = True
End Sub

Avatar of BeauT

ASKER

Well, that doesn't quite do what I need.  The idea is to have the image (or picture box) set to a defined height and width, say 1200 by 1200, and have the picture scaled to fit within it without spatial distortion.
paste image1 in  another picturebox "Picture2" sized like you want thunbnails to be..


Private Sub thumb(des As Object, source As Object, sPicname As String)
Set source.Picture = LoadPicture(sPicname)
x = 0.1

Do Until wide >= Picture2.ScaleWidth Or tall >= Picture2.ScaleHeight
    wide = source.Width * x
    tall = source.Height * x
    x = x + 0.1
Loop

des.Width = wide
des.Height = tall

des.Picture = source.Picture

End Sub


Private Sub File1_Click()
thumb Image1, Picture1, File1.Path & "\" & File1.FileName
End Sub
My latest effort...

'picture1 pasted inside picture2
'filelistbox to display pickfiles
'cmd btn saves thumbnail

Private Sub thumb(des As Object, picframe As Object, sPicname As String)
des.Visible = False
des.BorderStyle = 0
des.AutoRedraw = False
des.AutoSize = True
Set des.Picture = LoadPicture(sPicname)
x = 0.1

Do Until wide >= picframe.Width - 100 Or tall >= picframe.Height - 100
    wide = des.Width * x
    tall = des.Height * x
    x = x + 0.0001
Loop

des.AutoRedraw = True
des.Width = CInt(wide)
des.Height = CInt(tall)
des.Left = (picframe.ScaleWidth / 2) - (des.ScaleWidth / 2)
des.Top = (picframe.ScaleHeight / 2) - (des.ScaleHeight / 2)
des.Visible = True
des.PaintPicture des.Picture, 0, 0, wide, tall ', 50, 50, 10, 10
des.Picture = des.Image

End Sub

Private Sub cmdsavethumb_Click()
SavePicture Picture1.Picture, File1.Path & "\" & "thumb" & Left(File1.FileName, Len(File1.FileName) - 3) & "bmp"
End Sub

Private Sub File1_Click()
thumb Picture1, Picture2, File1.Path & "\" & File1.FileName
End Sub

Private Sub Form_Load()
File1.Path = "D:\Webpage" 'your path here
File1.Pattern = "*.gif;*.bmp;*.jpg"
Picture2.Height = Picture2.Width
End Sub

Avatar of BeauT

ASKER

Inteqam, if you can include the full VB declaration for the DrawIconEx API call, then I think your answer will be right.
Avatar of BeauT

ASKER

jbil, I need a few things clarified...
-what exactly do you mean by "picture1 pasted inside picture2"?  Do you mean a picture box within a picturebox?
-the des and picrframe objects: what kinds of objects/controls are these?  I am assuming that they are picturebox controls, but I can't be sure exactly what you are doing there.

Thanx in advance.
yes a picturebox within a picturebox.
the des is a picturebox "picture1" that will display the thumbnail in the size set by picframe picture2"  changing the size of picture2 will affect the size of the thumbnail, but the thumbnail will always be inside of the frame. I used picboxes in order to save the smaller image after painting.
Avatar of BeauT

ASKER

OK, well I was able to use jbil's solution, slightly modified, to get what I needed.  jbil, if you want, I will ask another question so I can assign you points.  I still will give points to Inteqam if he/she provides me with the API declaration (always nice to know more than one way to skin a cat). :-)
The DrawIconEx function draws an icon or cursor in the client area of the window of the given device context, performing the specified raster operations, and stretching or compressing the icon or cursor as specified.

BOOL DrawIconEx(

    HDC  hdc,      // handle of device context
    int  xLeft,      // x-coordinate of upper left corner
    int  yTop,      // y-coordinate of upper left corner
    HICON  hIcon,      // handle of icon to draw
    int  cxWidth,      // width of the icon
    int  cyWidth,      // height of the icon
    UINT  istepIfAniCur,      // index of frame in animated cursor
    HBRUSH  hbrFlickerFreeDraw,      // handle of background brush
    UINT  diFlags      // icon-drawing flags
   );      
Parameters

hdc

Identifies the device context for a window.

xLeft

Specifies the logical x-coordinate of the upper-left corner of the icon or cursor.

yTop

Specifies the logical y-coordinate of the upper-left corner of the icon or cursor.

hIcon

Identifies the icon or cursor to be drawn. This parameter can identify an animated cursor. The icon or cursor resource must have been previously loaded by using the LoadImage function.

cxWidth

Specifies the logical width of the icon or cursor.

cyWidth

Specifies the logical height of the icon or cursor.

istepIfAniCur

Specifies the index of the frame to draw, if hIcon identifies an animated cursor. This parameter is ignored if hIcon does not identify an animated cursor.

hbrFlickerFreeDraw

Identifies a brush that the system uses for flicker-free drawing. If hbrBkgnd is a valid brush handle, the system creates an offscreen bitmap using the given brush for the background color, draws the icon or cursor into the bitmap, and then copies the bitmap into the device context identified by hdc. If hbrBkgnd is NULL, the system draws the icon or cursor directly into the device context.

diFlags

Specifies the drawing flags. This parameter can be one of the following values:

Value      Meaning
DI_COMPAT      Draws the icon or cursor using the system default image rather than the user-specified image.
DI_DEFAULTSIZE      Draws the icon or cursor in its default width, ignoring the cxWidth and cyWidth parameters.
DI_IMAGE      Performs the raster operation specified by ropImage.
DI_MASK      Performs the raster operation specified by ropMask.
DI_NORMAL      Combination of DI_IMAGE and DI_MASK.
Return Value

If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. To get extended error information, call GetLastError.

Remarks

DrawIconEx places the icon's upper-left corner at the location specified by the xLeft and yTop parameters. The location is subject to the current mapping mode of the device context.
and sorry for late


Avatar of BeauT

ASKER

Iteqam, sorry to have to keep rejecting your answers, but I need the API call in the VB format. I don't know how to interpret the code you posted into VB nor do I know the .DLL or alias to declare it as. Also, I need to know what values to set the constants as. If you could provide that info I'd be very appreciative. Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Inteqam
Inteqam

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BeauT

ASKER

Cool! Thanx 100-fold. But PLEASE do remember to send me the constant values. I can't do much at all without them.
#define DI_MASK         0x0001
#define DI_IMAGE        0x0002
#define DI_NORMAL       0x0003
#define DI_COMPAT       0x0004
#define DI_DEFAULTSIZE  0x0008