<small id='HC5ub'></small><noframes id='HC5ub'>

    <i id='HC5ub'><tr id='HC5ub'><dt id='HC5ub'><q id='HC5ub'><span id='HC5ub'><b id='HC5ub'><form id='HC5ub'><ins id='HC5ub'></ins><ul id='HC5ub'></ul><sub id='HC5ub'></sub></form><legend id='HC5ub'></legend><bdo id='HC5ub'><pre id='HC5ub'><center id='HC5ub'></center></pre></bdo></b><th id='HC5ub'></th></span></q></dt></tr></i><div id='HC5ub'><tfoot id='HC5ub'></tfoot><dl id='HC5ub'><fieldset id='HC5ub'></fieldset></dl></div>
        <bdo id='HC5ub'></bdo><ul id='HC5ub'></ul>
      <tfoot id='HC5ub'></tfoot>
    1. <legend id='HC5ub'><style id='HC5ub'><dir id='HC5ub'><q id='HC5ub'></q></dir></style></legend>
    2. 在 C# 中旋转图像时如何防止剪切?

      How do I prevent clipping when rotating an image in C#?(在 C# 中旋转图像时如何防止剪切?)
      <tfoot id='exkCK'></tfoot>

          <legend id='exkCK'><style id='exkCK'><dir id='exkCK'><q id='exkCK'></q></dir></style></legend>
            <bdo id='exkCK'></bdo><ul id='exkCK'></ul>

            <i id='exkCK'><tr id='exkCK'><dt id='exkCK'><q id='exkCK'><span id='exkCK'><b id='exkCK'><form id='exkCK'><ins id='exkCK'></ins><ul id='exkCK'></ul><sub id='exkCK'></sub></form><legend id='exkCK'></legend><bdo id='exkCK'><pre id='exkCK'><center id='exkCK'></center></pre></bdo></b><th id='exkCK'></th></span></q></dt></tr></i><div id='exkCK'><tfoot id='exkCK'></tfoot><dl id='exkCK'><fieldset id='exkCK'></fieldset></dl></div>

            <small id='exkCK'></small><noframes id='exkCK'>

              <tbody id='exkCK'></tbody>

                本文介绍了在 C# 中旋转图像时如何防止剪切?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我刚刚经历了一堆东西,试图弄清楚如何让图像甚至旋转.这行得通,但现在它正在剪辑,我不确定如何让它停止......我正在使用这个 rotateImage 方法:

                I just went through a bunch of stuff trying to figure out how to get the image to even rotate. That works but now it's clipping and I'm not really sure how to make it stop... I'm using this rotateImage method:

                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(bmp);
                
                        //now we set the rotation point to the center of our image
                        gfx.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);
                
                        //now rotate the image
                        gfx.RotateTransform(rotationAngle);
                
                        gfx.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.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;
                
                        //now draw our new image onto the graphics object
                        gfx.DrawImage(img, new System.Drawing.Point(0, 0));
                
                        //dispose of our Graphics object
                        gfx.Dispose();
                
                        //return the image
                        return bmp;
                    }
                

                我尝试将空位图放大,但这只适用于一侧,因为图像固定在位图的左上角.任何想法将不胜感激!

                I tried making the empty bitmap larger but that only works for one side since the image is pinned to the upper left corner of the bitmap. Any ideas would be appreciated!

                推荐答案

                我从另一个网站找到了一些帮助.以下是我最终为那些想知道的人所做的:

                I found some help from another website. Here's what I ended up doing for those of you who want to know:

                // Rotates the input image by theta degrees around center.
                    public static Bitmap RotateImage(Bitmap bmpSrc, float theta)
                    {
                        Matrix mRotate = new Matrix();
                        mRotate.Translate(bmpSrc.Width / -2, bmpSrc.Height / -2, MatrixOrder.Append);
                        mRotate.RotateAt(theta, new System.Drawing.Point(0, 0), MatrixOrder.Append);
                        using (GraphicsPath gp = new GraphicsPath())
                        {  // transform image points by rotation matrix
                            gp.AddPolygon(new System.Drawing.Point[] { new System.Drawing.Point(0, 0), new System.Drawing.Point(bmpSrc.Width, 0), new System.Drawing.Point(0, bmpSrc.Height) });
                            gp.Transform(mRotate);
                            System.Drawing.PointF[] pts = gp.PathPoints;
                
                            // create destination bitmap sized to contain rotated source image
                            Rectangle bbox = boundingBox(bmpSrc, mRotate);
                            Bitmap bmpDest = new Bitmap(bbox.Width, bbox.Height);
                
                            using (Graphics gDest = Graphics.FromImage(bmpDest))
                            {  // draw source into dest
                                Matrix mDest = new Matrix();
                                mDest.Translate(bmpDest.Width / 2, bmpDest.Height / 2, MatrixOrder.Append);
                                gDest.Transform = mDest;
                                gDest.DrawImage(bmpSrc, pts);
                                return bmpDest;
                            }
                        }
                    }
                
                    private static Rectangle boundingBox(Image img, Matrix matrix)
                    {
                        GraphicsUnit gu = new GraphicsUnit();
                        Rectangle rImg = Rectangle.Round(img.GetBounds(ref gu));
                
                        // Transform the four points of the image, to get the resized bounding box.
                        System.Drawing.Point topLeft = new System.Drawing.Point(rImg.Left, rImg.Top);
                        System.Drawing.Point topRight = new System.Drawing.Point(rImg.Right, rImg.Top);
                        System.Drawing.Point bottomRight = new System.Drawing.Point(rImg.Right, rImg.Bottom);
                        System.Drawing.Point bottomLeft = new System.Drawing.Point(rImg.Left, rImg.Bottom);
                        System.Drawing.Point[] points = new System.Drawing.Point[] { topLeft, topRight, bottomRight, bottomLeft };
                        GraphicsPath gp = new GraphicsPath(points,
                                                                            new byte[] { (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)PathPointType.Line });
                        gp.Transform(matrix);
                        return Rectangle.Round(gp.GetBounds());
                    }
                

                这篇关于在 C# 中旋转图像时如何防止剪切?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                Cannot remove items from ListBox(无法从列表框中删除项目)
                Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)

                  • <bdo id='qmXXc'></bdo><ul id='qmXXc'></ul>
                      <tbody id='qmXXc'></tbody>
                  • <small id='qmXXc'></small><noframes id='qmXXc'>

                      <tfoot id='qmXXc'></tfoot>

                        <legend id='qmXXc'><style id='qmXXc'><dir id='qmXXc'><q id='qmXXc'></q></dir></style></legend>
                        • <i id='qmXXc'><tr id='qmXXc'><dt id='qmXXc'><q id='qmXXc'><span id='qmXXc'><b id='qmXXc'><form id='qmXXc'><ins id='qmXXc'></ins><ul id='qmXXc'></ul><sub id='qmXXc'></sub></form><legend id='qmXXc'></legend><bdo id='qmXXc'><pre id='qmXXc'><center id='qmXXc'></center></pre></bdo></b><th id='qmXXc'></th></span></q></dt></tr></i><div id='qmXXc'><tfoot id='qmXXc'></tfoot><dl id='qmXXc'><fieldset id='qmXXc'></fieldset></dl></div>