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

张掖网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站设计等网站项目制作,到程序开发,运营维护。创新互联成立与2013年到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联。
常用的WPF图像处理包括缩放、裁切和旋转等,如下是一个将图像旋转90度的例子。
- var imageStreamSource = 
 File.OpenRead(@"r:\1\24.bmp");    - var decoder = BitmapDecoder.Create
 (imageStreamSource, BitmapCreate
 Options.PreservePixelFormat, 
 BitmapCacheOption.Default);    - var bitmapFrame = decoder.Frames[0];   
 - TransformedBitmap myRotated
 BitmapSource = new TransformedBitmap();    - myRotatedBitmapSource.BeginInit();   
 - myRotatedBitmapSource.Source = 
 bitmapFrame;    - // 旋转90度   
 - myRotatedBitmapSource.Transform = 
 new RotateTransform(90);    - myRotatedBitmapSource.EndInit();   
 - //旋转   
 - var rotate = new RotateTransform(90);  
 - var rotatedBitMap = new Trans
 formedBitmap(bitmapFrame, rotate);    - image1.Source = rotatedBitMap;   
 - ////裁剪  
 - //CroppedBitmap chainedBitMap = 
 new CroppedBitmap(bitmapFrame,
 new Int32Rect(100, 0, (int)bitmap
 Frame.Width - 100, (int)bitmap
 Frame.Height));    - ////缩放  
 - //var scare = new ScaleTransform
 (1.5, 2);   - //var scaredBitMap = new Trans
 formedBitmap(bitmapFrame, scare);    - var encoder = new JpegBitmapEncoder();  
 - encoder.Frames.Add(BitmapFrame.
 Create(rotatedBitMap));   - //encoder.Frames.Add(BitmapFrame.
 Create(scaredBitMap));   - //encoder.Frames.Add(BitmapFrame.
 Create(chainedBitMap));   - encoder.Save(File.Create
 (@"r:\1\3.jpg"));   
和上面的WPF图像处理例子相比,这里就是多了一个TransformedBitmap变换,其实这和xaml中的变换时一样的。
 
 
   
  
  - < Image Width="150" Margin="5" 
Grid.Column="0" Grid.Row="1">      
  
  - < Image.Source>   
   
  
  - < TransformedBitmap Source="
/sampleImages/watermelon.jpg" >      
  
  - < TransformedBitmap.Transform>   
   
  
  - < RotateTransform Angle="90"/>   
   
  
  - < /TransformedBitmap.Transform>   
   
  
  - < /TransformedBitmap>   
   
  
  - < /Image.Source>   
   
  
  - < /Image>  
  
 
其它变换也都可以参照xaml中WPF图像处理方式进行,这里就不过多介绍了。
            
            网页题目:几种常用WPF图像处理方法介绍            
            链接地址:
http://www.cdxtjz.cn/article/cdgjpgi.html