|
-
Jan 4th, 2011, 04:03 AM
#1
Thread Starter
Member
vb6 program like windows picture and fax viewer..help
happy new year to you all,
i have a program that views pictures. The pictures could have different sizes. Some are bigger than the screen size, some are smaller than that. I want to display the entire content of the picture in image control or picture control like windows pic and fax viewer does:
i tried this but it failed to work:
Code:
Option Explicit
Private Sub Form_Load()
Dim scrw As Double
Dim scrh As Double
Dim imgw As Double
Dim imgh As Double
scrw = Screen.Width / Screen.TwipsPerPixelX
scrh = Screen.Height / Screen.TwipsPerPixelY
imgw = Image1.Width / 15
imgh = Image1.Height / 15
MsgBox Image1.Width
If imgw > scrw Then
Image1.Width = Screen.Width
Me.Move 0, 0
Else
Me.Width = Image1.Width
End If
If imgh > scrh Then
Image1.Height = Screen.Height
Me.Move 0, 0
Else
Me.Height = Image1.Height
End If
Me.Width = Image1.Width
Me.Height = Image1.Height
Me.Top = 0
Me.Left = 0
End Sub
Private Sub Image1_Click()
Unload Me
End Sub
NB: picture is added to image1 from database application. How does these thing work please?
-
Jan 4th, 2011, 08:50 AM
#2
Re: vb6 program like windows picture and fax viewer..help
A couple things.
1) Make sure your image control's stretch property is True
2) Trying to size a control larger than its form/container will result in control clipped on right & bottom
3) Size your control to the form's ScaleWidth & ScaleHeight (its inside width/height), not the screen size
4) You may want to use proportional scaling when setting the size of your image control, otherwise it will look stretched out
-- Use VB's ScaleX & ScaleY to get actual image size
Code:
imgW = ScaleX(Image1.Picture.Width, vbHimetric, vbTwips)
imgH = ScaleY(Image1.Picture.Height, vbHimetric, vbTwips)
-
Jan 4th, 2011, 01:29 PM
#3
Thread Starter
Member
Re: vb6 program like windows picture and fax viewer..help
 Originally Posted by LaVolpe
A couple things.
1) Make sure your image control's stretch property is True
2) Trying to size a control larger than its form/container will result in control clipped on right & bottom
3) Size your control to the form's ScaleWidth & ScaleHeight (its inside width/height), not the screen size
4) You may want to use proportional scaling when setting the size of your image control, otherwise it will look stretched out
-- Use VB's ScaleX & ScaleY to get actual image size
Code:
imgW = ScaleX(Image1.Picture.Width, vbHimetric, vbTwips)
imgH = ScaleY(Image1.Picture.Height, vbHimetric, vbTwips)
10x a lot buddy. You did open my eyes. My initial mistake was that I was doing this:
Code:
bigimage.picture=imgthumb.picture
where imgthumb.picture accepts path of the file. Now I passed the actual file path to the full screen file as well.
then the code is like this:
Code:
Option Explicit
Private Sub Form_Activate()
Dim scrw As Double
Dim scrh As Double
Dim imgw As Double
Dim imgh As Double
Dim ftop As Integer
Dim fleft As Integer
'1px=15twips
scrw = Screen.Width / Screen.TwipsPerPixelX
scrh = Screen.Height / Screen.TwipsPerPixelY
imgw = ScaleX(Image1.Picture.Width, vbHimetric, vbPixels)
imgh = ScaleY(Image1.Picture.Height, vbHimetric, vbPixels)
If imgw > scrw Then 'width greater
Width = Screen.Width - 5
fleft = 0
Else
fleft = Screen.Width / 2
Width = ScaleX(imgw, vbPixels, vbTwips)
End If
If imgh > scrh Then
Height = Screen.Height - 5
ftop = 0
Else
Height = ScaleX(imgh, vbPixels, vbTwips)
ftop = Screen.Height / 2
End If
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
Image1.Width = Me.Width
Image1.Height = Me.Height
End Sub
Private Sub Image1_Click()
Unload Me
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|