CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Zoom

  1. #1
    Join Date
    Jun 2001
    Location
    India
    Posts
    6

    Zoom

    Hello,

    I want to zoom a image in picture box. Either i can zoom to particular levels or click & drag a window in the picture box, which maximizes the selected (picked) image.

    Thanks


  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Zoom

    Here's How you do it:


    Dim ViewLft as Integer, ViewTop as Integer
    Dim ViewWid as Integer, ViewHgt as Integer
    Dim Zoom as Single

    private Sub ComputeDim()
    ViewWid = picView.Width / Zoom
    ViewHgt = picView.Height / Zoom
    If ViewWid > picImage.Width then ViewWid = picImage.Width
    If ViewHgt > picImage.Height then ViewHgt = picImage.Height
    End Sub

    private Sub ShowImage()
    picView.Cls
    picView.PaintPicture picImage.Image, 0, 0, ViewWid * Zoom, ViewHgt * Zoom, ViewLft, ViewTop, ViewWid, ViewHgt
    End Sub

    private Sub Form_Load()
    ViewLft = 0
    ViewTop = 0
    Zoom = 1
    ComputeDim
    ShowImage
    End Sub

    private Sub picView_MouseDown(Button as Integer, Shift as Integer, X as Single, Y as Single)
    If Button = vbLeftButton then
    Zoom = Zoom + 0.5
    else
    Zoom = Zoom - 0.5
    End If
    If Zoom < 0.5 then Zoom = 0.5
    ComputeDim
    ShowImage
    End Sub




    There are two pictureboxes, picImage, a hidden picturebox that contains the original image, and picView that is used to show the image. Set Autoredraw of both pictureboxes equal to True.

    Using click and drag to select the zoom region is just a matter of selecting ViewTop, ViewLft, ViewWid and ViewHgt appropriately. Hope you can do it.



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

Featured