旋转图像修改的分辨率和清晰度 [英] rotating an image modifies the resolution and clarity

查看:291
本文介绍了旋转图像修改的分辨率和清晰度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的代码来旋转图像。



的问题是图像的分辨率越来越低,图像是越来越不清楚。



我如何避免这个问题?

 私人位图rotateImage(位图b,飘角)
{
//创建一个新的空位图来保存旋转后的图像
位图returnBitmap =新位图(b.Width,b.Height);
//使图形从空位
图形G = Graphics.FromImage(returnBitmap)对象;
//旋转点移动到图片$ B $的中心B g.TranslateTransform((浮点)this.Width / 2,(浮点)this.Height / 2);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
//旋转
g.RotateTransform(角度);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
g.TranslateTransform( - (浮点)this.Width / 2, - (浮点)this.Height / 2);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
//绘制图像传递到图形对象
g.DrawImage(B,新点(0,0));
g.Dispose();
返回returnBitmap;
}


解决方案

反复旋转会导致质量下降,因为反复插值造成死亡的形象。为了避免这种情况的最好办法是只有一次旋转源图像。如果你正在构建中的图像被旋转多次的系统只需通过的总转动量,而不是每次都采用小三角形旋转到一个已经旋转图像旋转源图像。


Consider the code below to rotate an image.

The problem is the resolution of the image is getting low and the image is getting unclear.

How can I avoid this problem?

private Bitmap rotateImage(Bitmap b, float angle)
{
    //create a new empty bitmap to hold rotated image
    Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
    //make a graphics object from the empty bitmap
    Graphics g = Graphics.FromImage(returnBitmap);
    //move rotation point to center of image
    g.TranslateTransform((float)this.Width / 2, (float)this.Height / 2);
    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
    //rotate
    g.RotateTransform(angle);
    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
    g.TranslateTransform(-(float)this.Width / 2, -(float)this.Height / 2);
    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
    //draw passed in image onto graphics object
    g.DrawImage(b, new Point(0, 0));
    g.Dispose();
    return returnBitmap;
}

解决方案

Repeated rotations will cause quality to drop as the repeated interpolations take their toll on the image. The best way to avoid this is to only rotate the source image once. If you're building a system in which an image gets rotated multiple times simply rotate the source image by the total rotation amount instead of applying small delta rotations to an already rotated image each time.

这篇关于旋转图像修改的分辨率和清晰度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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