首页 > Windows开发 > 详细

wpf,vb,位图剪裁的方法

时间:2015-12-18 06:29:33      阅读:306      评论:0      收藏:0      [点我收藏+]
‘ 貌似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)

 

wpf,vb,位图剪裁的方法

原文:http://www.cnblogs.com/NuclearBoy/p/5055779.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!