如果有人能够非常友好地向我展示如何在保存时将图片大小限制为指定尺寸(例如150 x 200像素),我会很高兴。如果不满足,则错误消息应指示所需的维度。
但是,以下是将图片上传到图片框的代码。
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Try
OpenFileDialog1.ShowDialog()
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
img = OpenFileDialog1.FileName.ToString
Catch
End Try
End Sub
答案 0 :(得分:1)
If Image.FromFile(OpenFileDialog1.FileName).Size.Width > 150 Or Image.FromFile(OpenFileDialog1.FileName).Size.Height > 200 Then
lblPhotoErr.Text = "More than 150 x 200"
bError = True
End If