博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FrameAreaImage control
阅读量:6357 次
发布时间:2019-06-23

本文共 4974 字,大约阅读时间需要 16 分钟。

最近在项目中,需要把一个中空的图片放大绘制(图片如下),而不失真。

 

试了picture congtrol,但是失真。最终我用customize control解决了问题。

代码里面见真相。

 

1:  using System;
2:  using System.Collections.Generic;
3:  using System.ComponentModel;
4:  using System.Drawing;
5:  using System.Data;
6:  using System.Linq;
7:  using System.Text;
8:  using System.Windows.Forms;
9:  using System.Drawing.Drawing2D;
10:   
13:      public partial class FrameAreaImage : Control
14:      {
15:          #region [ Private Members... ]
16:          private int ConerLength = 40;
17:          private int FrameImageEdgeLength = 30;
18:          #endregion
19:          #region [ Constructors / Destructors... ]
20:          public FrameAreaImage()
21:          {
22:              InitializeComponent();
23:          }
24:          #endregion
25:          #region [ Accessors / Manipulators... ]
26:          public Bitmap Image
27:          {
28:              get;
29:              set;
30:          }
31:   
32:          public int FrameShadowSize
33:          {
34:              get;
35:              set;
36:          }
37:          #endregion
38:          #region [ Overrides... ]
39:   
40:          protected override void OnPaint(PaintEventArgs e)
41:          {
42:              Graphics g = e.Graphics;
43:   
44:              if (Image != null)
45:              {
46:                  //
47:                  // Draw the Corner
48:                  //
49:                  var image = Image.Clone(new Rectangle(0, 0, ConerLength, ConerLength),
50:                                          System.Drawing.Imaging.PixelFormat.Format32bppArgb);
51:                  // TopLeft
52:                  g.DrawImage(image, 0, 0, ConerLength, ConerLength);
53:                  image.Dispose();
54:   
55:   
56:                  // Left Bottom
57:                  image = Image.Clone(new Rectangle(0, Image.Height - ConerLength, ConerLength, ConerLength),
58:                                      System.Drawing.Imaging.PixelFormat.Format32bppArgb);
59:                  g.DrawImage(image, new Point(1, this.Height - ConerLength));
60:                  image.Dispose();
61:   
62:                  // Right Bottom
63:                  image = Image.Clone(new Rectangle(Image.Width - ConerLength, Image.Height - ConerLength, ConerLength, ConerLength),
64:                                      System.Drawing.Imaging.PixelFormat.Format32bppArgb);
65:                  g.DrawImage(image, new Point(this.Width - ConerLength, this.Height - ConerLength));
66:                  image.Dispose();
67:   
68:                  // Top Right
69:                  image = Image.Clone(new Rectangle(Image.Width - ConerLength, 0, ConerLength, ConerLength),
70:                                          System.Drawing.Imaging.PixelFormat.Format32bppArgb);
71:                  g.DrawImage(image, new Point(this.Width - ConerLength, 0));
72:                  image.Dispose();
73:   
74:                  //
75:                  // Draw the Edge Shadow
76:                  //
77:
78:                  // Left
79:                  image = Image.Clone(new Rectangle(0, ConerLength, FrameShadowSize, FrameImageEdgeLength),
80:                                          System.Drawing.Imaging.PixelFormat.Format32bppArgb);
81:                  TextureBrush tBrush = new TextureBrush(image);
82:                  tBrush.WrapMode = WrapMode.TileFlipY;
83:                  g.FillRectangle(tBrush, new Rectangle(0, ConerLength, FrameShadowSize, this.Height - 2 * ConerLength));
84:                  image.Dispose();
85:                  tBrush.Dispose();
86:   
87:                  // Bottom
88:                  g.DrawImage(Image.Clone(new Rectangle(FrameImageEdgeLength, Image.Height - FrameShadowSize, FrameImageEdgeLength, FrameShadowSize),
89:                                          System.Drawing.Imaging.PixelFormat.Format32bppArgb),
90:                                          ConerLength - 2, this.Height - FrameShadowSize - 1, this.Width - 2 * ConerLength + ConerLength / 2, FrameShadowSize);
91:   
92:
93:                     g.DrawImage(Image.Clone(new Rectangle(Image.Width - FrameShadowSize, ConerLength, FrameShadowSize, FrameImageEdgeLength),
94:                                          System.Drawing.Imaging.PixelFormat.Format32bppArgb),
95:                                          this.Width - FrameShadowSize - 1, ConerLength - 2, FrameShadowSize, this.Height - 2 * ConerLength + ConerLength / 2);
96:   
97:                  // Top
98:                  g.DrawImage(Image.Clone(new Rectangle(FrameImageEdgeLength, 0, FrameImageEdgeLength, FrameShadowSize),
99:                              System.Drawing.Imaging.PixelFormat.Format32bppArgb),
100:                              ConerLength, 0, this.Width - 2 * ConerLength + FrameShadowSize, FrameShadowSize);
101:              }
102:   
103:              base.OnPaint(e);
104:          }
105:          #endregion
106:      }

转载于:https://www.cnblogs.com/jalenwang/archive/2011/10/22/2221273.html

你可能感兴趣的文章
Zabbix监控可视化
查看>>
infobright中导入数据避免特殊字符问题
查看>>
SCCM 2012系列11 补丁分发下
查看>>
UWP 入门教程2——如何实现自适应用户界面
查看>>
如何永久的修改主机名
查看>>
Windows Server 2008 R2 远程桌面服务RDS和VDI介绍
查看>>
【Java学习笔记】集合框架的学习
查看>>
产生式编程(Generative Programming)方法介绍
查看>>
Facebook Detectron物体检测研究平台实践
查看>>
构建和谐网络--关注网络安全
查看>>
微软新的杰作:Windows Embedded Compact 7
查看>>
一个菜鸟级项目经理眼里的团队建设
查看>>
下一代RDS技术预览版RemoteFX实测体验
查看>>
SharePoint 补丁
查看>>
浏览器下管理Linux系统--记webmin的使用
查看>>
Conversion to Dalvik format failed with error 1的又一种情形
查看>>
统一沟通-技巧-5-Lync 2010 for iPhone iPad–配置-手册
查看>>
Powershell管理系列(七)删除Exchange用户邮箱中多余的电子邮件地址
查看>>
为C++程序添加文件保存加载功能
查看>>
网贷之家的爬虫之旅
查看>>