开发者

slicing a jpg with vb.net

开发者 https://www.devze.com 2022-12-14 04:11 出处:网络
since i do not have any image editing software, 开发者_Python百科i am going to use vb.net to slice an image horizontally. can someone help me get started please?In the code below you first load the im

since i do not have any image editing software, 开发者_Python百科i am going to use vb.net to slice an image horizontally. can someone help me get started please?


In the code below you first load the image, then create a new image with the new width and height, grab the Graphics object from it and finally draw the old image onto the new image. We draw the old image onto the new image using the old image's dimensions but since the new image is smaller the rest will be off of the canvas.

    Private Shared Sub CropImage(ByVal inputImagePath As String, ByVal outputImagePath As String, ByVal newHeight As Integer)
    Using oldImage = System.Drawing.Image.FromFile(inputImagePath)
        Using NewImage As New System.Drawing.Bitmap(oldImage.Width, newHeight)
            Using G = Graphics.FromImage(NewImage)
                G.DrawImage(oldImage, 0, 0, oldImage.Width, oldImage.Height)
                NewImage.Save(outputImagePath, System.Drawing.Imaging.ImageFormat.Jpeg)
            End Using
        End Using
    End Using
End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消