gpt4 book ai didi

c# - 使用矩阵变换(旋转)图像 - 设计时与运行时渲染结果

转载 作者:行者123 更新时间:2023-11-30 16:36:12 25 4
gpt4 key购买 nike

我有一张 48x48 的图像,它使用变换矩阵进行了旋转。

出于某种原因,设计时的旋转图像与运行时的旋转图像不同,您可以从 this screenshot (link dead) 中看到(左边是设计时,右边是运行时):

它可能有点难以发现,但如果您仔细观察蓝色圆圈的右边缘,它在右侧图像中大约宽一个像素。请注意,图像是分层的 - 前景中的白光是正在旋转的部分,而背景中的蓝色球是静止的。

看起来图像在运行时偏移了 1 个像素,旋转正好 90 度(如屏幕截图所示)、180 度,也可能是 270 度。据我所知,图像在任何其他旋转角度下看起来都一样。

这是一个片段:

protected static Image RotateImage(Image pImage, Single pAngle)
{
Matrix lMatrix = new Matrix();
lMatrix.RotateAt(pAngle, new PointF(pImage.Width / 2, pImage.Height / 2));
Bitmap lNewBitmap = new Bitmap(pImage.Width, pImage.Height);
lNewBitmap.SetResolution(pImage.HorizontalResolution, pImage.VerticalResolution);
Graphics lGraphics = Graphics.FromImage(lNewBitmap);
lGraphics.Transform = lMatrix;
lGraphics.DrawImage(pImage, 0, 0);
lGraphics.Dispose();
lMatrix.Dispose();
return lNewBitmap;
}

void SomeMethod()
{
// Same results in design-time and run-time:
PictureBox1.Image = RotateImage(PictureBox2.Image, 18)
// Different results in design-time and run-time.
PictureBox1.Image = RotateImage(PictureBox2.Image, 90)
}

谁能解释这种行为的原因?或者更好的是,一种使运行时结果看起来像设计时结果的解决方案?

这对我来说很重要,因为此图像是动画的一部分,该动画是根据基于单个图像的代码生成的,然后以小步旋转。在设计时,动画看起来流畅漂亮。在运行时,它看起来像是在跳来跳去:/

我在 Windows Vista Business SP2 上使用 Visual Studio 2005。

最佳答案

这可能与设计时使用的 Graphics 对象与运行时的差异有关,例如 PixelOffsetMode。

关于c# - 使用矩阵变换(旋转)图像 - 设计时与运行时渲染结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1124105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com