我可以在没有这些工件的情况下使用graphics.RotateTransform()吗?
问题描述:
我正在执行seminal article中描述的颜色选择器组件。我可以在没有这些工件的情况下使用graphics.RotateTransform()吗?
正如你所看到的,我已经掌握了一些基本排序:
一个不过的要求,就是要有任意量旋转的色轮的能力。认为这是容易的,我的一些算术鼠标位置 - >色值代码和下面的代码位,实际上油漆轮:
newGraphics.TranslateTransform((float)this.Radius, (float)this.Radius);
newGraphics.RotateTransform((float)this.offset);
newGraphics.TranslateTransform((float)this.Radius * -1, (float)this.Radius * -1);
不幸的是,旋转这样的位图实际上产生这样的:
请注意出现在中心两侧的文物。
我使用了错误的方法吗?或者有没有办法摆脱这些讨厌的撕裂?
答
查看该示例的源代码,我对UpdateDisplay
方法进行了以下更改,方法是添加一个矩阵并设置RotateAt
方法。
private void UpdateDisplay() {
// Update the gradients, and place the
// pointers correctly based on colors and
// brightness.
using (Brush selectedBrush = new SolidBrush(selectedColor)) {
using (Matrix m = new Matrix()) {
m.RotateAt(35f, centerPoint);
g.Transform = m;
// Draw the saved color wheel image.
g.DrawImage(colorImage, colorRectangle);
g.ResetTransform();
}
// Draw the "selected color" rectangle.
g.FillRectangle(selectedBrush, selectedColorRectangle);
// Draw the "brightness" rectangle.
DrawLinearGradient(fullColor);
// Draw the two pointers.
DrawColorPointer(colorPoint);
DrawBrightnessPointer(brightnessPoint);
}
}
它旋转的轮35度(虽然选色是关断现在通过,以及,35度,因为我没惹所有的代码),并且它不产生任何撕裂。
不是100%肯定这是答案(但评论太长),所以这可能有帮助。
+0
我不知道为什么这样做应该是不同的,但现在撕开了。谢谢拉尔斯! – 2012-02-02 23:03:38
这是一些非常脏的撕裂。旋转轮本身的一种替代方法是将旋转量传递给填充圆上颜色的任何函数,然后相应地调整色轮而不需要进行变换。 – aardvarkk 2012-02-02 18:34:45
我无法重新创建您现在描述的问题。您可以尝试将Graphics.PixelOffsetMode设置为PixelOffsetMode.Half。让我知道它是否有帮助。 – 2012-02-02 19:35:08
@aardvarkk这听起来很有希望 - 我会看看其他选项。 – 2012-02-02 22:56:20