我正在尝试向Picturebox添加缩放功能和平移功能 [英] I am trying to add a zoom function and a pan function to a Picturebox
问题描述
我想使用Picturebox_MouseCaptureChange事件Arg放大PictureBox.Image的香料.帮助搜索说有一个缩放和平移功能
I want to Use Picturebox_MouseCaptureChange Event Arg to zoom in on a peice of a PictureBox.Image. The Help Search says there is a zoom and a pan function on
Systems.Windows.Controls
Systems.Windows.Controls
但是我无法在Visual Basic 2008版的添加引用组件中找到它.
But I cannot find it in the add reference component of the Visual Basic 2008 edition...
我有一个程序可以通过TrackBar进行缩放,这是...
I have one program that I did that allowed me to zoom using a TrackBar here it is...
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles tbZoom.Scroll
If tbZoom.Value > 1 Then
Dim newWidth As Integer = (picAshi.Width * 2)
Dim newHeight As Integer = (picAshi.Height * 2)
Dim b As Bitmap = New Bitmap(newWidth, newHeight)
Dim g As Graphics = Graphics.FromImage(b)
g.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
g.DrawImage(picAshi.Image, New Rectangle(1, 0, b.Width, b.Height), _
0, 0, picAshi.Width, picAshi.Height, GraphicsUnit.Pixel)
g.Dispose()
picAshi.Image = b
picAshi.Width *= 2
picAshi.Height *= 2
Else
Dim newWidth As Integer = (picAshi.Width / 2)
Dim newHeight As Integer = (picAshi.Height / 2)
Dim b As Bitmap = New Bitmap(newWidth, newHeight)
Dim g As Graphics = Graphics.FromImage(b)
g.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
g.DrawImage(picAshi.Image, New Rectangle(1, 0, b.Width, b.Height), _
0, 0, picAshi.Width, picAshi.Height, GraphicsUnit.Pixel)
g.Dispose()
picAshi.Image = b
picAshi.Width /= 2
picAshi.Height /= 2
End If
End Sub
问题是我无法使轨迹栏缩放到比控制器左上角更近的位置....我需要缩放然后平移图像.请帮助我...
The problem is that I cannot get the trackbar to zoom any closer that the top left side of the controler....I need to zoom and then pan around the image. Please Help Me...
推荐答案
我需要的是MouseCaptureChanged事件arg来保存图像的位置
What I need is the MouseCaptureChanged Event arg to hold the position of the Image
昏暗
newWidth 整数 '=(PictureBox.Width * 2 )
newWidth As Integer '= (PictureBox.Width * 2)
昏暗 newHeight As 整数 '=(picAshi.Height * 2 )
Dim newHeight As Integer '= (picAshi.Height * 2)
newWidth = PictureBox.MousePosition.X
newWidth = PictureBox.MousePosition.X
newHeight = PictureBox.MousePosition.Y
newHeight = PictureBox.MousePosition.Y
昏暗
b 位图= 新 位图(newWidth,newHeight)
b As Bitmap = New Bitmap(newWidth, newHeight)
昏暗 g As 图形= Graphics.FromImage(b)
Dim g As Graphics = Graphics.FromImage(b)
g.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
g.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
g.DrawImage(PictureBox.Image,
g.DrawImage(PictureBox.Image,
新 矩形(1,0,b.Width,b.Height),_
New Rectangle(1, 0, b.Width, b.Height), _
0、0,PictureBox.Width,PictureBox.Height,GraphicsUnit.Pixel)
0, 0, PictureBox.Width, PictureBox.Height, GraphicsUnit.Pixel)
g.Dispose()
g.Dispose()
PictureBox.Image = b
PictureBox.Image = b
PictureBox.Width * = 2
PictureBox.Width *= 2
PictureBox.Height * = 2
PictureBox.Height *= 2
这篇关于我正在尝试向Picturebox添加缩放功能和平移功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!