如何在vb中放大可滚动面板内的图像 [英] how to zoom in the image inside a scrollable panel in vb

查看:205
本文介绍了如何在vb中放大可滚动面板内的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可滚动的面板,里面有图片/图片框

I have a scrollable panel with an image/picture box inside.

我想放大并缩小图像而不是按钮消失在面板的左下方。顺便说一下,图片的实际尺寸。

I wanted to zoom in and zoom out the image without the buttons disappearing on the lower left of the panel. by the way, the image is in it's actual size.

如果我将它设为可以放大和缩小的可滚动面板,我仍然可以通过不使用屏幕坐标而不是实际图像的坐标来获取图像的坐标?

If I make it a scrollable panel that can be zoomed in and out, will i still be able to get the coordinates of the image by not using the coordinates of the screen but the coordinates of the actual image?

请帮助我

推荐答案

我不确定你的意思


在没有按钮消失的情况下放大和缩小图像

zoom in and zoom out the image without the buttons disappearing

但是你可以使用Bob Powell创建的这个控件。他的网站现在似乎已离线,但我发现此代码:

But you can use this control created by Bob Powell. His site seems to be offline now but I found this code:

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms


Namespace bobpowell.net
   '/ <summary>
   '/ ZoomPicBox does what it says on the wrapper.
   '/ </summary>
   '/ <remarks>
   '/ PictureBox doesn't lend itself well to overriding. Why not start with something basic and do the job properly?
   '/ </remarks>

   Public Class ZoomPicBox
    Inherits ScrollableControl

    Private _image As Image

    <Category("Appearance"), Description("The image to be displayed")>  _
    Public Property Image() As Image
     Get
      Return _image
     End Get
     Set
      _image = value
      UpdateScaleFactor()
      Invalidate()
     End Set
    End Property

    Private _zoom As Single = 1F

    <Category("Appearance"), Description("The zoom factor. Less than 1 to reduce. More than 1 to magnify.")>  _
    Public Property Zoom() As Single
     Get
      Return _zoom
     End Get
     Set
      If value < 0 OrElse value < 1E-05 Then
         value = 1E-05F
      End If
      _zoom = value
      UpdateScaleFactor()
      Invalidate()
     End Set
    End Property


    Private Sub UpdateScaleFactor()
     If _image Is Nothing Then
      Me.AutoScrollMargin = Me.Size
     Else
      Me.AutoScrollMinSize = New Size(CInt(Me._image.Width * _zoom + 0.5F), CInt(Me._image.Height * _zoom + 0.5F))
     End If
    End Sub 'UpdateScaleFactor

    Private _interpolationMode As InterpolationMode = InterpolationMode.High

    <Category("Appearance"), Description("The interpolation mode used to smooth the drawing")>  _
    Public Property InterpolationMode() As InterpolationMode
     Get
      Return _interpolationMode
     End Get
     Set
      _interpolationMode = value
     End Set
    End Property


    Protected Overrides Sub OnPaintBackground(pevent As PaintEventArgs)
    End Sub 'OnPaintBackground

    ' do nothing.

    Protected Overrides Sub OnPaint(e As PaintEventArgs)
     'if no image, don't bother
     If _image Is Nothing Then
      MyBase.OnPaintBackground(e)
      Return
     End If
     'Set up a zoom matrix
     Dim mx As New Matrix(_zoom, 0, 0, _zoom, 0, 0)
     mx.Translate(Me.AutoScrollPosition.X / _zoom, Me.AutoScrollPosition.Y / _zoom)
     e.Graphics.Transform = mx
     e.Graphics.InterpolationMode = _interpolationMode
     e.Graphics.DrawImage(_image, New Rectangle(0, 0, Me._image.Width, Me._image.Height), 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel)
     MyBase.OnPaint(e)
    End Sub 'OnPaint


    Public Sub New()
     'Double buffer the control
     Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)

     Me.AutoScroll = True
    End Sub 'New
   End Class 'ZoomPicBox
End Namespace 'bobpowell.net

这篇关于如何在vb中放大可滚动面板内的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆