C#如何旋转图片框中绘制的图像

时间:2016-06-17 16:46:39

标签: c# winforms paint onpaint

我在picturebox内绘制了以下图片( C#WinForms ):

enter image description here

这是Paint事件中的代码:

private void pbBox_Paint(object sender, PaintEventArgs e)
        {

            Rectangle leftInsertionBox = new Rectangle(_leftPadding, _topPadding + _boxBase, _insertion, _boxFront);

            Rectangle leftCoverBox = new Rectangle(_leftPadding + leftInsertionBox.Width, _topPadding + _boxBase, _boxBase, _boxFront);

            Rectangle leftTopDustBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width - (_insertion + _boxBase) / 2, _topPadding, (_insertion + _boxBase) / 2, _boxBase);
            Rectangle rightTopDustBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width + _boxHeight, _topPadding, (_insertion + _boxBase) / 2, _boxBase);

            Rectangle topRect = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width, _topPadding, _boxHeight, _boxBase);
            Rectangle frontRect = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width, _topPadding + _boxBase, _boxHeight, _boxFront);

            Rectangle leftBottomDustBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width - (_insertion + _boxBase) / 2, _topPadding + topRect.Height + frontRect.Height, (_insertion + _boxBase) / 2, _boxBase);
            Rectangle rightBottomDustBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width + _boxHeight, _topPadding + topRect.Height + frontRect.Height, (_insertion + _boxBase) / 2, _boxBase);

            Rectangle bottomRect = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width, _topPadding + _boxBase + _boxFront, _boxHeight, _boxBase);
            Rectangle backRect = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width, _topPadding + _boxBase + _boxFront + _boxBase, _boxHeight, _boxFront);

            Rectangle rightCoverBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width + _boxHeight, _topPadding + _boxBase + _boxFront + _boxBase, _boxBase, _boxFront);

            Rectangle rightInsertionBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width + _boxHeight + rightCoverBox.Width, _topPadding + topRect.Height + frontRect.Height + bottomRect.Height , _insertion, _boxFront);

            Rectangle bottomGlueBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width, _topPadding + topRect.Height + frontRect.Height + bottomRect.Height + backRect.Height, _boxHeight, _glue);

            // solid brush
            SolidBrush myBrush = new SolidBrush(System.Drawing.Color.LightGray);

            LinearGradientBrush linearGradientBrush = new LinearGradientBrush(topRect, Color.Red, Color.Yellow, 90);

            ColorBlend cblend = new ColorBlend(3);
            cblend.Colors = new Color[3]  { Color.Red, Color.Yellow, Color.Green };
            cblend.Positions = new float[3] { 0f, 0.5f, 1f };

            linearGradientBrush.InterpolationColors = cblend;


            using (Pen pen = new Pen(Color.DarkGray, 1))
            {
                //e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

                e.Graphics.DrawRectangle(pen, leftInsertionBox);
                e.Graphics.DrawRectangle(pen, leftCoverBox);

                e.Graphics.DrawRectangle(pen, leftTopDustBox);
                e.Graphics.DrawRectangle(pen, rightTopDustBox);
                e.Graphics.DrawRectangle(pen, leftBottomDustBox);
                e.Graphics.DrawRectangle(pen, rightBottomDustBox);

                e.Graphics.DrawRectangle(pen, topRect);
                e.Graphics.FillRectangle(myBrush, topRect.X+1,topRect.Y+1,topRect.Width-1,topRect.Height-1);

                e.Graphics.DrawRectangle(pen, frontRect);
                e.Graphics.FillRectangle(myBrush, frontRect.X + 1, frontRect.Y + 1, frontRect.Width - 1, frontRect.Height - 1);

                e.Graphics.DrawRectangle(pen, bottomRect);
                e.Graphics.FillRectangle(myBrush, bottomRect.X + 1, bottomRect.Y + 1, bottomRect.Width - 1, bottomRect.Height - 1);

                e.Graphics.DrawRectangle(pen, backRect);
                e.Graphics.FillRectangle(myBrush, backRect.X + 1, backRect.Y + 1, backRect.Width - 1, backRect.Height - 1);


                e.Graphics.DrawRectangle(pen, rightCoverBox);
                e.Graphics.DrawRectangle(pen, rightInsertionBox);

                e.Graphics.DrawRectangle(pen, bottomGlueBox);
            }
        }

我需要添加一个旋转场(角度),以便可以旋转图像:

enter image description here

  

关于如何旋转它的任何线索?

0 个答案:

没有答案
相关问题