Page 3 of 3 FirstFirst 123
Results 81 to 93 of 93

Thread: ZoomPictureBox: picture control with mouse-centred zooming

  1. #81

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    Hi Paul, welcome to VBForums.

    The ZoomPictureBox allows you to set the Image to Nothing and to call its Invalidate method in much the same way as a PictureBox. In both cases, the image source file remains locked. The safest way to avoid this is to read the image as a Stream instead of opening it with Image.FromFile(filename) or New Bitmap(filename).
    Code:
        Using stream As IO.Stream = IO.File.OpenRead(filename)
             ZoomPictureBoxName.Image = Image.FromStream(stream)
          End Using
    The source file is closed at the end of the Using block, so you are free to delete it independently of the image.

    BB

  2. #82
    New Member
    Join Date
    Aug 2021
    Posts
    3

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    I would like to contact the author of this library. I'm using the library in an application and need some information that I hope he can provide

  3. #83
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,683

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    Quote Originally Posted by davidgarnett View Post
    I would like to contact the author of this library. I'm using the library in an application and need some information that I hope he can provide
    BoopsBoops is the author of this software. This thread is the place to ask your questions

  4. #84
    New Member
    Join Date
    Aug 2021
    Posts
    3

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    Quote Originally Posted by .paul. View Post
    BoopsBoops is the author of this software. This thread is the place to ask your questions
    Paul,

    Thank you for your reply ... I'm new to VBForums. I thought I replied with my question to this thread.

    If I didn't, please let me know how to reply.

  5. #85
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,683

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    Quote Originally Posted by davidgarnett View Post
    Paul,

    Thank you for your reply ... I'm new to VBForums. I thought I replied with my question to this thread.

    If I didn't, please let me know how to reply.
    Yeah you're posting in the right place, but you haven't given any details with your comment. Boops Boops will need to know what it is you need to know....

  6. #86
    New Member
    Join Date
    Aug 2021
    Posts
    3

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    Quote Originally Posted by .paul. View Post
    Yeah you're posting in the right place, but you haven't given any details with your comment. Boops Boops will need to know what it is you need to know....
    There is no license information for ZPLib that I can find. Can the developer associate a license with the library? ... perhaps MIT?

  7. #87

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    Quote Originally Posted by davidgarnett View Post
    There is no license information for ZPLib that I can find. Can the developer associate a license with the library? ... perhaps MIT?
    That question applies to any code library, not just ZPLib. And it's not something I know much about. Please address your question to another forum such as Visual Basic .Net or C#.

    BB

  8. #88
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    844

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    Boops Boops, I think Davidgarnett want to know what is the license associated with your library/class to know if he can use it freely or not in his own applications.
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  9. #89

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    As far as I know all code posted in the CodeBank is unlicensed, so you are free use it however you like. if you include the code in a licensed project, it would be polite to add a comment referring to this thread or to my authorship. BB

  10. #90
    New Member
    Join Date
    Jan 2022
    Posts
    1

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    Hello, thank you for providing such great code.
    Unfortunately, the main post directs to post #75 to get the February 2019 version, but post #75 redirects back to the main post, which are two zip files, both from 2012, none of them with the newly added "DragMargin" property. There may have been a mix-up when editing posts. Would it be possible for OP to upload the new version? Thanks a lot.

  11. #91

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    Hi John, you are right. When I posted the last link nearly 3 years ago, I intended move it to post #1 where anyone could find it. But I discovered some errors and never got around to fixing them. Life got in the way... And then a month ago - even worse - I decided to clear out what seemed to be obsolete links in the thread. I forgot that the link in post #1 wasn't updated. What a mess: it took me quite a while to sort it out but now at least I have a new version with the following changes:

    1. SafeMargin works OK.
    2. The two separate files for the ZoomPictureBox class (Main and Properties) are now merged into one. Separating them seemed like a good idea at first but no longer.
    3. The panning and zooming for very large images works smoothly, but they can be very slow to load. There must be a better way. And very large images seem prone to throw OutOfMemory exceptions in Visual Studio 2022. That will take some work
    4. There was a problem with transparent backgrounds. I don't know if anyone noticed but it's fixed now.

    Here's an interim version of the ZoomPictureBox Class you may care try out:
    ZoomPictureBox_Jan2022.vb
    Questions, suggestions and criticism are welcome.

    BB

  12. #92
    Junior Member
    Join Date
    Aug 2024
    Posts
    30

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    Dear Boops Boops, The authour of this thread
    After downloading the files as per the instructions. I was so much thrilled as this was required
    Indeed Great work and remarkable achievement.

    Then i tried to develop an application but below coding generates error
    in ZoomPictureBox_Main1 DoubleClick Event and btnGetFrontImg_Click Event

    I've marked in Coding with Red mark and also pointed out the Error messages in quotes

    Will appreciate your help for the right corrections as i am using vb.net VS2019
    Code:
    Public Class ZoomingMovingImages
    
        Private _BaseImage As Image
        Private _AddImage As Image
    
        Public EmptyBitmapSize As New Size(500, 500)
    
        Private Sub ZoomingMovingImages_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          Call FormLayout()
        End Sub
    
        Private Sub FormLayout()
            'Set the PictureBox and ZoomPictureBox properties:
            PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
            PictureBox1.BorderStyle = BorderStyle.Fixed3D
            ZoomPictureBox_Main1.Parent = PictureBox1
            ZoomPictureBox_Main1.BackColor = Color.Transparent
            ZoomPictureBox_Main1.BorderStyle = BorderStyle.None
            ZoomPictureBox_Main1.Bounds = PictureBox1.ClientRectangle
    
            Dim zRect As Rectangle = ZoomPictureBox_Main1.ClientRectangle 'ZoomPictureBox1.ClientRectangle
            Dim bmp As New Bitmap(zRect.Width, zRect.Height)
            ZoomPictureBox_Main1.DrawToBitmap(bmp, zRect) 'ZoomPictureBox1.DrawToBitmap(bmp, zRect)
    
        End Sub
    
        Private Sub PictureBox1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            ZoomPictureBox_Main1.Bounds = PictureBox1.ClientRectangle
        End Sub
    
        Private Sub ZoomPictureBox_Main1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ZoomPictureBox_Main1.DoubleClick
            PictureBox1.Image = SuperimposeImage(_BaseImage, _AddImage, ZoomPictureBox_Main1.ImagePosition, ZoomPictureBox_Main1.ZoomFactor)
            ZoomPictureBox_Main1.ImagePosition = New Point(ZoomPictureBox_Main1.ImagePosition.X - 2, ZoomPictureBox_Main1.ImagePosition.Y - 2)
            Cursor.Position = New Point(Cursor.Position.X - 2, Cursor.Position.Y - 2)
        End Sub
    
    
        'Get an image from file or an empty bitmap:
        Private Function GetImage(ByVal currentImage As Image, ByVal emptyBitmapSize As Size, ByVal caption As String) As Image
            Dim bmp As Bitmap
            If currentImage Is Nothing Then
                bmp = New Bitmap(emptyBitmapSize.Width, emptyBitmapSize.Height)
            Else
                bmp = New Bitmap(currentImage)
            End If
            Using ofd As New OpenFileDialog
                ofd.Title = caption
                If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                    Try
                        bmp = New Bitmap(ofd.FileName)
                    Catch
                        MessageBox.Show("Invalid image file " & ofd.FileName)
                    End Try
                End If
            End Using
            Return bmp
        End Function
        Private Function SuperimposeImage(ByVal baseImage As Image, ByVal addImage As Image, ByVal location As Point, ByVal zoomFactor As Double) As Image
            If baseImage IsNot Nothing AndAlso addImage IsNot Nothing Then
                Using g As Graphics = Graphics.FromImage(baseImage)
                    g.DrawImage(addImage, location.X, location.Y,
                      CInt(addImage.Width * zoomFactor),
                      CInt(addImage.Height * zoomFactor))
                End Using
            End If
            Return baseImage
        End Function
    
        Private Sub SaveImage(ByVal img As Image)
            Using sfd As New SaveFileDialog
                sfd.Filter = "Image Files (*.png, *.jpg)|*.png;*.jpg"
                If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
                    If sfd.FileName.ToUpper.EndsWith("PNG") Then
                        _BaseImage.Save(sfd.FileName, Imaging.ImageFormat.Png)
                    ElseIf sfd.FileName.ToUpper.EndsWith("JPG") Then
                        _BaseImage.Save(sfd.FileName, Imaging.ImageFormat.Jpeg)
                    Else
                        MessageBox.Show("Please give a PNG or JPG extension. Other formats are not yet supported.")
                    End If
                End If
            End Using
        End Sub
    
        Private Sub btnGetImgFile_Click(sender As Object, e As EventArgs) Handles btnGetImgFile.Click
            _BaseImage = GetImage(PictureBox1.Image, EmptyBitmapSize, "Select base image")
            PictureBox1.Image = _BaseImage
            ZoomPictureBox_Main1.Bounds = PictureBox1.ClientRectangle
        End Sub
    
        Private Sub btnGetFrontImg_Click(sender As Object, e As EventArgs) Handles btnGetFrontImg.Click
            _AddImage = GetImage(ZoomPictureBox_Main1.Image, EmptyBitmapSize, "Select zoomable image")
            ZoomPictureBox_Main1.Image = _AddImage
    
        End Sub
    End Class
    I get Totally 8 errors

    ie below single single
    Handles ZoomPictureBox_Main1.DoubleClick : Handle Clause requires a with events variable defined in the containing type or one of its base types

    and below 7 with repeated messages in respective lines of syntaxes
    ImagePosition is is not a member of ZoomPictureBox_Main1
    ZoomFactor is not a member of ZoomPictureBox_Main1
    Image is is not a member of ZoomPictureBox_Main1

    Thankx
    nkvb
    Last edited by nkvb; Sep 26th, 2024 at 04:22 AM.

  13. #93
    Junior Member
    Join Date
    Aug 2024
    Posts
    30

    Re: ZoomPictureBox: picture control with mouse-centred zooming

    Boops Boops

    I've succeeded in resolving the issues as per #92.

    Wherever Errors cropping up have marked in RED and Underlined

    But now I am not able to access ZPBLib
    Imports ZPBlib GreenLine displaying under ZPBlib Although ZPBlib Project file Exists in Solution Explorer

    Now I've error coming up BC42025: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated at following line in below code

    Also GreenLine dispalying ZoomPictureBox_Main1.ZoomType

    'Below Trackbar I've used to Zoom the ZoomPicturebox

    Code:
    Imports ZPBlib
    Public Class ZoomingMovingImages
    
        Private _BaseImage As Image
        Private _AddImage As Image
    
        Public EmptyBitmapSize As New Size(500, 500)
    
        Private Sub ZoomingMovingImages_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          Call FormLayout()
        End Sub
    
        Private Sub FormLayout()
            'Set the PictureBox and ZoomPictureBox properties:
            PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
            PictureBox1.BorderStyle = BorderStyle.Fixed3D
            ZoomPictureBox_Main1.Parent = PictureBox1
            ZoomPictureBox_Main1.BackColor = Color.Transparent
            ZoomPictureBox_Main1.BorderStyle = BorderStyle.None
            ZoomPictureBox_Main1.Bounds = PictureBox1.ClientRectangle
    
            Dim zRect As Rectangle = ZoomPictureBox_Main1.ClientRectangle 'ZoomPictureBox1.ClientRectangle
            Dim bmp As New Bitmap(zRect.Width, zRect.Height)
            ZoomPictureBox_Main1.DrawToBitmap(bmp, zRect) 'ZoomPictureBox1.DrawToBitmap(bmp, zRect)
    
        End Sub
    
        Private Sub PictureBox1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            ZoomPictureBox_Main1.Bounds = PictureBox1.ClientRectangle
        End Sub
    
        Private Sub ZoomPictureBox_Main1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ZoomPictureBox_Main1.DoubleClick
            PictureBox1.Image = SuperimposeImage(_BaseImage, _AddImage, ZoomPictureBox_Main1.ImagePosition, ZoomPictureBox_Main1.ZoomFactor)
            ZoomPictureBox_Main1.ImagePosition = New Point(ZoomPictureBox_Main1.ImagePosition.X - 2, ZoomPictureBox_Main1.ImagePosition.Y - 2)
            Cursor.Position = New Point(Cursor.Position.X - 2, Cursor.Position.Y - 2)
        End Sub
    
    
        'Get an image from file or an empty bitmap:
        Private Function GetImage(ByVal currentImage As Image, ByVal emptyBitmapSize As Size, ByVal caption As String) As Image
            Dim bmp As Bitmap
            If currentImage Is Nothing Then
                bmp = New Bitmap(emptyBitmapSize.Width, emptyBitmapSize.Height)
            Else
                bmp = New Bitmap(currentImage)
            End If
            Using ofd As New OpenFileDialog
                ofd.Title = caption
                If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                    Try
                        bmp = New Bitmap(ofd.FileName)
                    Catch
                        MessageBox.Show("Invalid image file " & ofd.FileName)
                    End Try
                End If
            End Using
            Return bmp
        End Function
        Private Function SuperimposeImage(ByVal baseImage As Image, ByVal addImage As Image, ByVal location As Point, ByVal zoomFactor As Double) As Image
            If baseImage IsNot Nothing AndAlso addImage IsNot Nothing Then
                Using g As Graphics = Graphics.FromImage(baseImage)
                    g.DrawImage(addImage, location.X, location.Y,
                      CInt(addImage.Width * zoomFactor),
                      CInt(addImage.Height * zoomFactor))
                End Using
            End If
            Return baseImage
        End Function
    
        Private Sub SaveImage(ByVal img As Image)
            Using sfd As New SaveFileDialog
                sfd.Filter = "Image Files (*.png, *.jpg)|*.png;*.jpg"
                If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
                    If sfd.FileName.ToUpper.EndsWith("PNG") Then
                        _BaseImage.Save(sfd.FileName, Imaging.ImageFormat.Png)
                    ElseIf sfd.FileName.ToUpper.EndsWith("JPG") Then
                        _BaseImage.Save(sfd.FileName, Imaging.ImageFormat.Jpeg)
                    Else
                        MessageBox.Show("Please give a PNG or JPG extension. Other formats are not yet supported.")
                    End If
                End If
            End Using
        End Sub
    
        Private Sub btnGetImgFile_Click(sender As Object, e As EventArgs) Handles btnGetImgFile.Click
            _BaseImage = GetImage(PictureBox1.Image, EmptyBitmapSize, "Select base image")
            PictureBox1.Image = _BaseImage
            ZoomPictureBox_Main1.Bounds = PictureBox1.ClientRectangle
        End Sub
    
        Private Sub btnGetFrontImg_Click(sender As Object, e As EventArgs) Handles btnGetFrontImg.Click
            _AddImage = GetImage(ZoomPictureBox_Main1.Image, EmptyBitmapSize, "Select zoomable image")
            ZoomPictureBox_Main1.Image = _AddImage
    
        End Sub
    
    Private Sub ZoomSlider_Scroll(sender As Object, e As EventArgs) Handles ZoomSlider.Scroll
    
        ZoomPictureBox_Main1.EnableMouseWheelZooming = False
        ZoomPictureBox_Main1.EnableMouseDragging = False
    
        ZoomPictureBox_Main1.ZoomMode = ZoomPictureBox_Main1.ZoomType.ControlCenter
    
            If ZoomSlider.Value = 1 Then ZoomPictureBox_Main1.ZoomFactor = 1
            If ZoomSlider.Value = 2 Then ZoomPictureBox_Main1.ZoomFactor = 1.25
            If ZoomSlider.Value = 3 Then ZoomPictureBox_Main1.ZoomFactor = 1.5
            If ZoomSlider.Value = 4 Then ZoomPictureBox_Main1.ZoomFactor = 2
            If ZoomSlider.Value = 5 Then ZoomPictureBox_Main1.ZoomFactor = 2.5
    
    End Sub
    End Class
    Some Observations when trackbar scrolled No Doubt ZoomPictureBox_Main1 Displays all the images with respective zoomFactor
    and does not resemble as if zooming because smaller to larger all the images zoomed sized are displayed. How can all these Images with zoomed sized be cleared and resemble as Zooming

    your guidance and help shall be appreciated

    nkvb
    Last edited by nkvb; Sep 30th, 2024 at 12:51 AM.

Page 3 of 3 FirstFirst 123

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