zoukankan      html  css  js  c++  java
  • GDI+中启动双缓存后缩放失效的问题

    在写一个小的C# Form测试程序时遇到一个奇怪的问题,情况是这样:在启动双缓存情况下,利用画布的PageScale属性实现缩放功能,发现并没有效果。

    相关代码如下:

    启动双缓存:

    public Form1()
            {
                InitializeComponent();

                this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);

            }

    实现缩放功能:

    private void Form1_Paint(object sender, PaintEventArgs e)
            {

                // Create a rectangle.
                Rectangle rectangle1 = new Rectangle(20, 20, 50, 100);

                // Draw its outline.
                e.Graphics.DrawRectangle(Pens.SlateBlue, rectangle1);

                // Change the page scale. 
                e.Graphics.PageScale = 2.0F;

                // Call TranslateTransform to change the origin of the
                //  Graphics object.
                e.Graphics.TranslateTransform(10.0F, 10.0F);

                // Draw the rectangle again.
                e.Graphics.DrawRectangle(Pens.Tomato, rectangle1);

                // Set the page scale and origin back to their original values.
                e.Graphics.PageScale = 1.0F;
                e.Graphics.TranslateTransform(0.0F, 0.0F);

                SolidBrush transparentBrush = new SolidBrush(Color.FromArgb(50,
                    Color.Yellow));

                // Create a new rectangle with the coordinates you expect
                // after setting PageScale and calling TranslateTransform:
                // x = 10 + (20 * 2)
                // y = 10 + (20 * 2)
                // Width = 50 * 2
                // Length = 100 * 2
                Rectangle newRectangle = new Rectangle(50, 50, 100, 200);

                // Fill in the rectangle with a semi-transparent color.
                e.Graphics.FillRectangle(transparentBrush, newRectangle);

            }

    在网上搜索了相关问题,好像是这种使用方式存在问题,具体不详。

    目前采用的解决方法是,将图形绘制的代码封装在相应的类中,至于之前的问题的原因尚不明白,有了解的大侠望指教!

  • 相关阅读:
    BZOJ 1800 [Ahoi2009]fly 飞行棋
    BZOJ 3309 DZY Loves Math
    CAS Server和client 实现单点登录
    单点登录原理与简单实现
    Maven插件
    win10安装最新nexus-3.x及maven简单配置介绍
    oracle获取表的属性,包括字段,注释
    java 泛型详解-绝对是对泛型方法讲解最详细的,没有之一
    深入理解Tomcat虚拟目录
    环境搭建系列-系统安装之centos 6.5安装与配置
  • 原文地址:https://www.cnblogs.com/lizichao/p/2103083.html
Copyright © 2011-2022 走看看