几种常用WPF图像处理方法介绍
创始人
2024-06-18 00:50:36
0

WPF图像处理在试驾开发中是非常有用的一个工具。开发人员可以通过WPF图像处理简单的实现精美的图形界面显示功能。这里就为大家简单介绍一下。#t#

常用的WPF图像处理包括缩放、裁切和旋转等,如下是一个将图像旋转90度的例子。

 

  1. var imageStreamSource = 
    File.OpenRead(@"r:\1\24.bmp");   
  2. var decoder = BitmapDecoder.Create
    (imageStreamSource, BitmapCreate
    Options.PreservePixelFormat, 
    BitmapCacheOption.Default);   
  3. var bitmapFrame = decoder.Frames[0];   
  4. TransformedBitmap myRotated
    BitmapSource
     = new TransformedBitmap();   
  5. myRotatedBitmapSource.BeginInit();   
  6. myRotatedBitmapSource.Source = 
    bitmapFrame;   
  7. // 旋转90度   
  8. myRotatedBitmapSource.Transform = 
    new RotateTransform(90);   
  9. myRotatedBitmapSource.EndInit();   
  10. //旋转   
  11. var rotate = new RotateTransform(90);  
  12. var rotatedBitMap = new Trans
    formedBitmap(bitmapFrame, rotate);   
  13. image1.Source = rotatedBitMap;   
  14. ////裁剪  
  15. //CroppedBitmap chainedBitMap = 
    new CroppedBitmap(bitmapFrame,
    new Int32Rect(100, 0, (int)bitmap
    Frame.Width - 100, (int)bitmap
    Frame.Height));   
  16. ////缩放  
  17. //var scare = new ScaleTransform
    (1.5, 2);  
  18. //var scaredBitMap = new Trans
    formedBitmap(bitmapFrame, scare);   
  19. var encoder = new JpegBitmapEncoder();  
  20. encoder.Frames.Add(BitmapFrame.
    Create(rotatedBitMap));  
  21. //encoder.Frames.Add(BitmapFrame.
    Create(scaredBitMap));  
  22. //encoder.Frames.Add(BitmapFrame.
    Create(chainedBitMap));  
  23. encoder.Save(File.Create
    (@"r:\1\3.jpg"));  

 

和上面的WPF图像处理例子相比,这里就是多了一个TransformedBitmap变换,其实这和xaml中的变换时一样的。

 

  1. < Image Width="150" Margin="5" 
    Grid.Column="0" Grid.Row="1">   
  2. < Image.Source>   
  3. < TransformedBitmap Source="
    /sampleImages/watermelon.jpg" >   
  4. < TransformedBitmap.Transform>   
  5. < RotateTransform Angle="90"/>   
  6. < /TransformedBitmap.Transform>   
  7. < /TransformedBitmap>   
  8. < /Image.Source>   
  9. < /Image>  

 

其它变换也都可以参照xaml中WPF图像处理方式进行,这里就不过多介绍了。

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
Windows恶意软件20年“... 在Windows的早期年代,病毒游走于系统之间,偶尔删除文件(但被删除的文件几乎都是可恢复的),并弹...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
着眼MAC地址,解救无法享受D... 在安装了DHCP服务器的局域网环境中,每一台工作站在上网之前,都要先从DHCP服务器那里享受到地址动...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...