如何在vb.net中裁剪图像? [英] How to crop an image in vb.net?

查看:874
本文介绍了如何在vb.net中裁剪图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图像可以是任何东西。它可以是jpg,png,任何东西。

The image can be anything. It can be jpg, png, anything.

加载它。

裁剪它。假设从左侧删除前100个像素。

Crop it. Say removing first 100 pixels from the left.

保存到同一个文件

推荐答案

使用 Graphics.DrawImage方法(Image,RectangleF,RectangleF,GraphicsUnit)方法。

    Dim fileName = "C:\file.jpg"
    Dim CropRect As New Rectangle(100, 0, 100, 100)
    Dim OriginalImage = Image.FromFile(fileName)
    Dim CropImage = New Bitmap(CropRect.Width, CropRect.Height)
    Using grp = Graphics.FromImage(CropImage)
        grp.DrawImage(OriginalImage, New Rectangle(0, 0, CropRect.Width, CropRect.Height), CropRect, GraphicsUnit.Pixel)
        OriginalImage.Dispose()
        CropImage.Save(fileName)
    End Using

这篇关于如何在vb.net中裁剪图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆