Image Transformation in WPF输入日志标题
Image transformation is a process of rotating and scaling images.
Rotating Images
There are two ways to rotate an image. First option is to use the Rotation property of BitmapImage and second option is use a TransformBitmap image. The TransformBitmap class is use for both scaling and rotating images.
The Rotation property of BitmapImage is a type of Rotation enumeration that has four values Rotate0, Rotate90, Rotate180, and Rotate270. The following code snippet creates a BitmapImage element and set its Rotation attribute to Rotate270.
<Image HorizontalAlignment="Center">
<Image.Source>
<BitmapImage UriSource="Dock.jpg" Rotation="Rotate270" />
</Image.Source>
</Image>
Figure 44 shows the regular image and Figure 45 is the image rotates at 270 degrees.
Figure 45
Figure 46
Alternatively, we can use TransformBitmap and its Transform property to transform an image. The Source attribute of TransformedBitmap is the image name. To rotate an image, we simply need to set the Transform property to RotateTransform and set Angle attribute to the angle of rotation as shown in below code.
<Image >
<Image.Source>
<TransformedBitmap Source="Dock.jpg" >
<TransformedBitmap.Transform>
<RotateTransform Angle="90"/>
</TransformedBitmap.Transform>
</TransformedBitmap>
</Image.Source>
</Image>
The code listed in Listing 42 rotates an image at run-time.
private void RotateImageDynamically()
{
// Create an Image
Image imgControl = new Image();
// Create the TransformedBitmap
TransformedBitmap transformBmp = new TransformedBitmap();
// Create a BitmapImage
BitmapImage bmpImage = new BitmapImage();
bmpImage.BeginInit();
bmpImage.UriSource = new Uri(@"C:\Images\Dock.jpg", UriKind.RelativeOrAbsolute);
bmpImage.EndInit();
// Properties must be set between BeginInit and EndInit
transformBmp.BeginInit();
transformBmp.Source = bmpImage;
RotateTransform transform = new RotateTransform(90);
transformBmp.Transform = transform;
transformBmp.EndInit();
// Set Image.Source to TransformedBitmap
imgControl.Source = transformBmp;
LayoutRoot.Children.Add(imgControl);
}
Listing 42
Scaling Images
The ScaleTransform is used to scale an image. The ScaleX and ScaleY properties are used to resize the image by the given factor. For example, value 0.5 reduces the image size by 50% and value 1.50 stretches image by 150%. The CenterX and CenterY properties are used to set the point that is the center of the scaling. By default, CenterX and CenterY values are 0 and 0 that represents the top-left corner.
The following code snippet creates a BitmapImage element and set its ScaleTransform property and its attributes CenterX, CenterY, ScaleX, and ScaleY.
<Image Name="ImageControl" > <Image.Source> <TransformedBitmap Source="Dock.jpg" > <TransformedBitmap.Transform> <!--<RotateTransform Angle="90"/>--> <ScaleTransform CenterX="25" CenterY="25" ScaleX="2" ScaleY="2" /> </TransformedBitmap.Transform> </TransformedBitmap> </Image.Source> </Image>
用代码获取资源图片的方法:
public static BitmapImage GetImageIcon(System.Drawing.Bitmap bitmap, double angle)
{
BitmapImage bitmapImage = new BitmapImage(); try
{ System.IO.MemoryStream ms = new System.IO.MemoryStream();
bitmap.Save(ms, bitmap.RawFormat);
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
bitmapImage.Freeze(); }
catch (Exception ex)
{
ShowErrorMessage(ex);
} return bitmapImage;
}
Image Transformation in WPF输入日志标题的更多相关文章
- HTML6注册表单输入日志标题
一.找到元素. var d = document.getElementById("") var d = document.getElementsByName("" ...
- 扒一扒各大电商网站的m站都用的什么前端技术输入日志标题
凡客首页使用Swiper和zepto,没有使用jquery , 静态首页+js交互, 资源加载使用 lazyLoad X-AspNet-Version: 4.0.30319 X-AspNetMvc- ...
- HTML4如何让一个DIV居中对齐?float输入日志标题
float:left,right clear:both 如何让一个DIV居中对齐? 第一步:设置外层的DIV的text-align:center; 第二步:设置里层的DIV的margin:auto 以 ...
- Oracle 安装报错 [INS-06101] IP address of localhost could not be determined 解决方法输入日志标题
安装Oracle 11gR2,报错:[INS-06101] IP address of localhost could not be determined 出现这种错误是因为主机名和/etc/host ...
- MySQL的共享锁阻塞会话案例浅析输入日志标题
这是问题是一个网友遇到的问题:一个UPDATE语句产生的共享锁阻塞了其他会话的案例,对于这个案例,我进一步分析.总结和衍化了相关问题.下面分析如有不对的地方,敬请指正.下面是初始化环境和数据的 ...
- VisualSVN设置提交时必须输入日志信息
VisualSVN设置提交时必须输入日志信息 1.svn提交时强制输入提交信息 为了阻止SVN提交空日志信息和垃圾文件可以在SVN服务器端强制必须填写日志信息,这时需用到pre-commit钩子脚本. ...
- 正则表达式——WPF输入控件TextBox 限定输入特定字符
概念: 正则表达式是对字符串操作的一种逻辑公式, 就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符串”, 这个“规则字符串”用来表达对字符串的一种过滤逻辑. 目的: 给定一个正 ...
- SVN提交强制输入日志信息
在团队开发时,因一些团队成员提交代码时没有写提交说明的习惯,为了规范版本管理,增强大家的团队意识,上网找到了强制录入提交日志的方法.方法如下: 一.编写bat文件,命名为pre-commit.bat, ...
- WPF 实现带标题的TextBox
这篇博客将分享在WPF中如何创建一个带Title的TextBox.首先请看一下最终的效果, 实现思路:使用TextBlock+TextBox来实现,TextBlock用来显示Title. 实现代码, ...
随机推荐
- javascript测试
s阿道夫. 撒旦法 sd sad sd 的萨法a dsa发 fds sdfad 电风扇爱的方式爱的方式啊
- NYOJ题目65另一种阶乘问题
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsIAAAJhCAIAAADE+EHOAAAgAElEQVR4nO3drXLjSAMu4HMT4bmQYF
- CocoaPods 安装
虽然网上关于CocoaPods安装教程多不胜数,但是我在安装的过程中还是出现了很多错误,所以大家可以照下来步骤装一下,我相信会很好用. 前言 在iOS项目中使用第三方类库可以说是非常常见的事,但是要正 ...
- .net学习笔记---xml基础知识
一.XML简介 XML是一种标记语言,用于描述数据,它提供一种标准化的方式来来表示文本数据.XML文档以.xml为后缀.需要彻底注意的是XML是区分大小写的. 先从一个简单的XML例子来了解下xml基 ...
- 【Javascript】IE8兼容 背景图片与a标签的onclick事件
先说几句牢骚话. 虽然IE8比之IE6.7有很大的进步,但是在执行效率.兼容性上仍然有很多问题.被广大开发者喜爱的平台才是好平台. 可惜多亏当年盗版XP打开中国的计算机市场,IE作为一款捆绑软件仍然在 ...
- Swing布局基础
虽然很简单,但还是记录一下,以备复查. 1.BorderLayout ,这是JFrame的默认布局方式,基于此的新组件,例如BUTTON,可以放在东西南北中的某一个位置,如果不指定,则默认是中央.中央 ...
- 攻城狮在路上(壹) Hibernate(一)--- 软件环境、参考书目等一览表
1.环境配置: web容器:tomcat6.0 JDK:1.7.0_51 hibernate:4.2.0.Final 操作系统:WIN8 64位 数据库:mysql Ver 14.12 Distri ...
- zoj 3882 博弈 *
看了半天约数居然包括1,水了 #include<cstdio> #include<iostream> #include<algorithm> #include< ...
- Effective C++ 之 Item 3:尽可能使用 const
Effective C++ Chapter 1. 让自己习惯C++(Accustoming Yourself to C++) Item 3. 尽可能使用 const (Use const whenev ...
- HDU 4005 The war Tarjan+dp
The war Problem Description In the war, the intelligence about the enemy is very important. Now, o ...