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的简介和入门程序
    Mybatis的分页插件PageHelper的使用
    SQLyog 快捷键总结
    如何查看开发项目框架的版本信息
    Linux find命令示例 30
    转:数据库索引原理------MemCached
    array_merge 和 + 的区别
    [介绍]PHP设计模式:DAO(数据访问对象模式)
    PHP业务逻辑层和数据访问层设计
  • 原文地址:https://www.cnblogs.com/NuclearBoy/p/5055779.html
Copyright © 2011-2022 走看看