简体   繁体   English

在VB.Net中放大将SizeMode设置为Stretch的PictureBox

[英]Zooming in a PictureBox with SizeMode set to Stretch in VB.Net

So I have a pictureManager program I am creating for class. 因此,我有一个正在为类创建的pictureManager程序。 The pictureBox used for viewing the images has to have SizeMode set to stretch as to the professor's specs. 用于查看图像的pictureBox必须将SizeMode设置为可根据教授的规范进行拉伸。 I can't figure out how to use my hsb and vsb values to zoom the image. 我不知道如何使用我的hsb和vsb值来缩放图像。 He calls it "cropping" but really its just a zoom on the image, but I can't seem to get this to work when I click my apply button. 他称其为“裁剪”,但实际上只是图像的缩放,但是当我单击“应用”按钮时,我似乎无法使它起作用。 I've tried various solutions I found online, but I can't seem to get it to work. 我已经尝试过在网上找到的各种解决方案,但似乎无法使其正常工作。 Could someone could show me how to take the pictureBox.Image and zoom it and then return it to pictureBox.Image? 有人可以告诉我如何拍摄pictureBox.Image并缩放它,然后将其返回给pictureBox.Image吗? Thanks! 谢谢!

As my comment said: Place the picturebox inside of a panel. 正如我的评论所说:将图片框放在面板中。 I furthermore added a trackbar control with Minimum = 1 and Maximum = 10 on the form and enable AutoScroll on the Panel. 我还添加了一个跟踪栏控件,该控件在表单上的Minimum = 1和Maximum = 10,并在面板上启用了AutoScroll。 To zoom you just need this code if you set the Picturebox.Sizemode to StretchImage 要进行缩放,如果将Picturebox.Sizemode设置为StretchImage,则只需要此代码。

Public Class Form1
Private Sub AdjustSize()
    Dim zoommult As Double = TrackBar1.Value
    PictureBox1.Width = CInt(PictureBox1.Image.Width * zoommult)
    PictureBox1.Height = CInt(PictureBox1.Image.Height * zoommult)
End Sub
Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
    AdjustSize()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    AdjustSize()
End Sub
End Class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM