什么是最快的方法,而不会裁剪边缘与GDI +旋转图像? [英] What is the fastest method for rotating an image without clipping its edges with GDI+?

查看:176
本文介绍了什么是最快的方法,而不会裁剪边缘与GDI +旋转图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些一长串饿算法,这样做的,但由于我却没有拿出或发现任何东西特别快。

There are some looooong and hungry algorithms for doing so, but as of yet I haven't come up with or found anything particularly fast.

推荐答案

下面就是我最后做(广泛的不断研发量后,通过在$ C $盛泰提供了有益的链接):

Here's what I ended up doing (after an extensive amount of continued research, and the helpful link provided by TheCodeKing):

public Image RotateImage(Image img, float rotationAngle)
    {
        // When drawing the returned image to a form, modify your points by 
        // (-(img.Width / 2) - 1, -(img.Height / 2) - 1) to draw for actual co-ordinates.

        //create an empty Bitmap image 
        Bitmap bmp = new Bitmap((img.Width * 2), (img.Height *2));

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

        //set the point system origin to the center of our image
        gfx.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);

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

        //move the point system origin back to 0,0
        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;

        //draw our new image onto the graphics object with its center on the center of rotation
        gfx.DrawImage(img, new PointF((img.Width / 2), (img.Height / 2)));

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

        //return the image
        return bmp;
    }

干杯!

这篇关于什么是最快的方法,而不会裁剪边缘与GDI +旋转图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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