zoukankan      html  css  js  c++  java
  • FrameAreaImage control

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

    image 
    试了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:      }
  • 相关阅读:
    兴趣遍地都是,专注和持之以恒才是真正稀缺的
    vuecli2和vuecli3项目中添加网页标题图标
    vue+sentry 前端异常日志监控
    从零构建vue项目(三)--vue常用插件
    从零构建vue项目(一)--搭建node环境,拉取项目模板
    dbvisualizer安装
    TS学习笔记----(一)基础类型
    基于weui loading插件封装
    UI组件--element-ui--全部引入和按需引入
    vue_全局注册过滤器
  • 原文地址:https://www.cnblogs.com/jalenwang/p/2221273.html
Copyright © 2011-2022 走看看