zoukankan      html  css  js  c++  java
  • c# winform 应用编程代码总结 7

    24、-在一个区域中剪辑

            private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
            {
                // Create a path that consists of a single polygon.
                Point[] polyPoints = {
                                         new Point(10, 10),
                                         new Point(150, 10), 
                                         new Point(100, 75),
                                         new Point(100, 150)};
                GraphicsPath path = new GraphicsPath();
                path.AddPolygon(polyPoints);

                // Construct a region based on the path.
                Region region = new Region(path);

                // Draw the outline of the region.
                Pen pen = Pens.Black;
                e.Graphics.DrawPath(pen, path);

                // Set the clipping region of the Graphics object.
                e.Graphics.SetClip(region, CombineMode.Replace);

                // Draw some clipped strings.
                FontFamily fontFamily = new FontFamily("Arial");
                Font font = new Font(
                    fontFamily,
                    36, FontStyle.Bold,
                    GraphicsUnit.Pixel);
                SolidBrush solidBrush = new SolidBrush(Color.FromArgb(255, 255, 0, 0));
                //e.Graphics.Clip=region;
                e.Graphics.DrawString(
                    "A Clipping Region",
                    font, solidBrush,
                    new PointF(15, 25));

                e.Graphics.DrawString(
                    "A Clipping Region",
                    font,
                    solidBrush,
                    new PointF(15, 68));
            }

            效果:

            image

    25、使用颜色再变换表(改变图像中某种图片的颜色)

            private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
            {
                Image image = new Bitmap("..\\..\\test.bmp");
                int width = image.Width;
                int height = image.Height;
                e.Graphics.DrawImage(image, 10, 10, width, height);

                ColorMap colorMap = new ColorMap();
                colorMap.OldColor = Color.FromArgb(255, 255, 0, 0);  // opaque red
                colorMap.NewColor = Color.FromArgb(255, 0, 0, 255);  // opaque blue
                ColorMap[] remapTable = {colorMap};

                ImageAttributes  imageAttributes = new ImageAttributes();
                imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

                e.Graphics.DrawImage(
                    image, 
                    new Rectangle(180, 10, width, height),  // destination rectangle
                    0, 0,        // upper-left corner of source rectangle
                    width,       // width of source rectangle
                    height,      // height of source rectangle
                    GraphicsUnit.Pixel,
                    imageAttributes);        
            }

            效果:

            image

    26、消除文本的走样现象

            private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
            {
                FontFamily  fontFamily = new FontFamily("Times New Roman");
                Font font = new Font
                    fontFamily,
                    32, 
                    FontStyle.Regular,
                    GraphicsUnit.Pixel);
                SolidBrush  solidBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
                string string1 = "SingleBitPerPixel";
                string string2 = "AntiAlias";

                e.Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
                e.Graphics.DrawString(string1, font, solidBrush, new PointF(10, 10));

                e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                e.Graphics.DrawString(string2, font, solidBrush, new PointF(10, 60));
            }

            效果图:

             image

    27、绘制垂直文本

            private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

             {
                string text = "Vertical text";
                PointF pointF = new PointF(40, 10);
                FontFamily fontFamily = new FontFamily("Lucida Console");
                Font font = new Font(
                            fontFamily,
                            14,
                            FontStyle.Regular,
                            GraphicsUnit.Point);
                StringFormat stringFormat = new StringFormat();
                stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;

                SolidBrush solidBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
                e.Graphics.DrawString(text, font, solidBrush, pointF, stringFormat);

            }

    本系列文章是作者学习《Visual C#.NET 应用编程150例》(源码)心得笔记,欢迎转载,请注明原文地址,如有疑问,可以通过 278250658@qq.com 联系作者本人。

  • 相关阅读:
    drf-自动生成接口文档
    drf-Xadmin的使用
    drf自定义异常与封装response对象
    drf多表操作
    drf分页器
    drf认证权限频率过滤排序
    drf路由组件
    mysql中使用sql语句统计日志计算每天的访问量
    windows下MySQL忘记密码重置root密码的解决办法
    jquery中for循环一共几种
  • 原文地址:https://www.cnblogs.com/syxchina/p/2197279.html
Copyright © 2011-2022 走看看