Results 1 to 3 of 3

Thread: vb6 program like windows picture and fax viewer..help

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2010
    Posts
    37

    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?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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)
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2010
    Posts
    37

    Re: vb6 program like windows picture and fax viewer..help

    Quote Originally Posted by LaVolpe View Post
    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
  •  



Click Here to Expand Forum to Full Width