我必须弃权吗?我应该怎么做?

时间:2015-08-11 09:04:52

标签: vb.net dispose

使用以下代码缩放图像

While PictureBox1.Image.Height < ScreenHeight
      PictureBox1.Image = New Bitmap(Image1, PictureBox1.Image.Width * 1.003, PictureBox1.Image.Height * 1.003)
      Me.PictureBox1.Update()
End While

我是否需要在循环中dispose(但是如何保留我的图像呢?)或者只在循环外部处理一次就足够了吗?

我是否使用Picturebox1.Image.Dispose()

我是否还需要使用PictureBox1.Image = Nothing

感谢您提供有用的信息

2 个答案:

答案 0 :(得分:0)

这似乎运作良好

Dim Width, Height As Integer
Width = PictureBox1.Image.Width
Height = PictureBox1.Image.Height
While Height < ScreenHeight And (Microsoft.VisualBasic.DateAndTime.Timer - StartTime) < ScreenSaverDuration
      PictureBox1.Image = New Bitmap(Image1, Width * 1.003, Height * 1.003)
      Width = PictureBox1.Image.Width
      Height = PictureBox1.Image.Height
      Me.PictureBox1.Update()
      PictureBox1.Image.Dispose()
End While

答案 1 :(得分:0)

Dim Height As Integer = PictureBox1.Image.Height
Dim Width As Integer = PictureBox1.Image.Width
While PictureBox1.Image.Height < ScreenHeight
    Height *= 1.003
    Width *= 1.003
End While
PictureBox1.Image = New Bitmap(Image1, Width, Height)
PictureBox1.Update()