如何在vb.net中调整图像大小

时间:2016-03-22 06:05:37

标签: .net vb.net

我的代码调整了图片大小,但它只能减小尺寸。

 For Each oFile In My.Computer.FileSystem.GetFiles(parm_strTargetPath)
                If oFile.ToString.ToLower.Contains(".png") Or oFile.ToString.ToLower.Contains(".jpg") Or oFile.ToString.ToLower.Contains(".jpeg") Then
                    Dim strFileName = System.IO.Path.GetFileName(oFile)
                    Try
                        Dim original As Image = Image.FromFile(oFile)
                        Dim resized As Image = ResizeImage(original, New Size(h, w))
                        Dim memStream As MemoryStream = New MemoryStream()
                        resized.Save(memStream, ImageFormat.Jpeg)

                        Dim file As New FileStream(result & "/" & strFileName , FileMode.Create, FileAccess.Write)
                        memStream.WriteTo(file)
                        file.Close()
                        memStream.Close()
                    Catch ex As Exception

                    End Try

                End If

            Next

我的图片尺寸:1028x 172,我希望调整为500 x 500 但结果是图片大小:500x84 如何将图片从1028x 172调整为500 x 500? 谢谢大家。

1 个答案:

答案 0 :(得分:-1)

 Dim resized As Image = ResizeImage(original, New Size(h, w), False)

而不是

 Dim resized As Image = ResizeImage(original, New Size(h, w))