如何在windowsform中将矩形倾斜到45度 [英] How to tilt rectangle to 45 degree in windowsform

查看:89
本文介绍了如何在windowsform中将矩形倾斜到45度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



有人能告诉我是否有可能在Windows窗体中将矩形控制旋转到一定程度......?就像我想将矩形旋转到45度左右,我可以实现这个目标......?



提前致谢。





代码如下:





Hi all,

Can anybody tell me is it possible to rotate rectangle control to certain degrees in windows form...? Like i want to rotate the rectangle to around 45 degrees, so can i achieve this...?

Thanks in advance.


The code is as follows:


private void Form1_Load(object sender, EventArgs e)
 {
 Image img = pictureBox1.Image;       
 RotateImage(img, 45);
 }

     public static Image RotateImage(Image img, float rotationAngle)
        {
            //create an empty Bitmap image
            Bitmap bmp = new Bitmap(img.Width, img.Height);

            //turn the Bitmap into a Graphics object
            Graphics gfx = Graphics.FromImage(img);

            //gfx.Clear(Color.Transparent);

           
            //now we set the rotation point to the center of our image
            gfx.TranslateTransform((float)img.Width / 2, (float)img.Height / 2);

            //now rotate the image
            gfx.RotateTransform(rotationAngle);

            gfx.TranslateTransform(-(float)img.Width / 2, -(float)img.Height / 2);

            //set the InterpolationMode to HighQualityBicubic so to ensure a high
            //quality image once it is transformed to the specified size
            gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
            //gfx.Clear(Color.White);
            //now draw our new image onto the graphics object
            gfx.DrawImage(img, new Point(0, 0));

            //dispose of our Graphics object
            gfx.Dispose();

            //return the image
            return img;
        
    }

推荐答案

查看此链接。



http://stackoverflow.com/questions/2163829 /怎么做-c-rotate-a-picture-in-c-sharp [ ^ ]


这篇关于如何在windowsform中将矩形倾斜到45度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆