wpf,vb,位图剪裁的方法

‘ 貌似WPF对GDI+不提供支持,要达到剪裁图像的方法,可以使用image.clip,
’不过clip只是对图片的一个遮挡拦截效果,并不改变本身的图片资源。
下面的代码提供了剪裁图片资源的方法。




Dim path = "C:\Users\Administrator\Desktop\image\image\Images\tori_gaku_02.png" Dim bitmap As BitmapSource = New BitmapImage(New Uri(path, UriKind.Absolute)) '获得位图宽度,高度 Dim width = bitmap.PixelWidth Dim height = bitmap.PixelHeight Dim bytePerPixel = bitmap.Format.BitsPerPixel / 8 Dim stride = width * bytePerPixel '储存位图像素信息 Dim pixls(stride * height + 1) As Byte Dim dpix = bitmap.DpiX Dim dpiy = bitmap.DpiY Dim format = bitmap.Format 'PixelFormats.Bgr32 ' Dim palette = bitmap.Palette ' Nothing '设置剪切矩形 Dim cut As New Int32Rect(0, 0, width * 0.25, height * 0.25) Dim cut2 As New Int32Rect(width * 0.25, height * 0.25, width * 0.25, height * 0.25) '复制指定区域像素信息 bitmap.CopyPixels(cut2, pixls, stride, 0) '用法2:bitmap.CopyPixels(pixls, stride, 0) '根据复制的像素信息,新建一个位图 Dim image As BitmapSource = BitmapSource.Create(width * 0.25, height * 0.25, dpix, dpiy, format, palette, pixls, stride) '新建一个image控件,显示剪裁的位图 Dim image2 As New Image image2.Stretch = Stretch.Fill image2.Width = width * 0.25 image2.Height = height * 0.25 image2.Source = image grid1.Children.Add(image2)

 

转载于:https://www.cnblogs.com/NuclearBoy/p/5055779.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值