zoukankan      html  css  js  c++  java
  • wpf,vb,位图剪裁的方法

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




    Dim path = "C:UsersAdministratorDesktopimageimageImages ori_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)
  • 相关阅读:
    python 文件目录/方法
    python文件
    python模块
    python数据结构
    python函数
    python迭代器和生成器
    python循环语句
    python控制语句 if
    python数字
    个人课程总结
  • 原文地址:https://www.cnblogs.com/NuclearBoy/p/5055779.html
Copyright © 2011-2022 走看看