图像居中CenterImage
来源:互联网 发布:西安云计算 编辑:程序博客网 时间:2024/05/16 06:18
Code:
基类XMarksTheSpot(支持打印):
using System;using System.Windows.Forms;using System.Drawing;using System.Drawing.Printing;using System.Drawing.Drawing2D;namespace CsStudy{ class XMarksTheSpot : Form { public static void Main() { Application.Run(new XMarksTheSpot()); } public XMarksTheSpot() { Text = this.Name; ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs e) { DoPage(e.Graphics, ForeColor, ClientSize.Width, ClientSize.Height); base.OnPaint(e); } protected override void OnClick(EventArgs e) { PrintDocument prndoc = new PrintDocument(); prndoc.DocumentName = Text; prndoc.PrintPage += new PrintPageEventHandler(prndoc_PrintPage); prndoc.Print();//打印 base.OnClick(e); } void prndoc_PrintPage(object obj, PrintPageEventArgs e) { Graphics grph = e.Graphics; SizeF sizef = grph.VisibleClipBounds.Size; DoPage(grph, Color.Black, (int)sizef.Width, (int)sizef.Height); } protected virtual void DoPage(Graphics grph, Color clr, int cx, int cy) { //图形保真 grph.SmoothingMode = SmoothingMode.None; grph.PixelOffsetMode = PixelOffsetMode.Default; } }}
子类:
using System;using System.Windows.Forms;using System.Drawing;namespace CsStudy{ class CenterImage : XMarksTheSpot { Image image; new static void Main() { Application.Run(new CenterImage()); } CenterImage() { Text = "图像居中"; image = Image.FromFile(@"F:\photo\网络图片\123.jpg"); } protected override void DoPage(Graphics grph, Color clr, int cx, int cy) { grph.DrawImage(image, (cx - image.Width) / 2, (cy - image.Height) / 2,image.Width,image.Height); } }}
效果图:
0 0
- 图像居中CenterImage
- 图像居中
- emgu 图像处理-版型居中
- 关于highChart图形中,环形图像,文字居中的处理
- iOS每日一记之---------- 图像 放大 居中 裁剪
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- C# 图像居中缩放(自动裁剪保证图像不被压扁或变长)
- ckeditor image align center customization(ckeditor 编辑器图像属性居中设置)
- %00截断问题
- ios排序知识点函数
- 利用Rational Rose进行C++代码和数据库结构分析
- GridView相关总结(主键绑定 行高亮 状态替换 多余字符...替代 详情查看 )
- hadoop-Reduce侧联结
- 图像居中CenterImage
- Hadoop-基于DistributedCache的复制联结
- 什么是真正的朋友
- python yield
- 国外知名的开源项目托管网站
- 使用Python下载Voxforge语音文件
- 如何设置windows 2003的最大远程连接数
- Git的基本使用和安装
- 检测点2.1