【问题标题】:Can I use graphics.RotateTransform() without these artifacts?我可以在没有这些工件的情况下使用 graphics.RotateTransform() 吗?
【发布时间】:2012-02-25 10:02:02
【问题描述】:

我正在实现seminal article 中描述的颜色选择器组件。

如您所见,我已经整理了基础知识:

然而,其中一个要求是能够让色轮旋转任意量。认为这很容易,我对鼠标位置进行了一些算术运算 -> 颜色值代码,并将以下代码用于实际绘制轮子的位:

newGraphics.TranslateTransform((float)this.Radius, (float)this.Radius);
newGraphics.RotateTransform((float)this.offset);
newGraphics.TranslateTransform((float)this.Radius * -1, (float)this.Radius * -1);

不幸的是,像这样旋转位图实际上会产生这样的结果:

注意出现在中心两侧的人工制品。

我是否使用了错误的方法?或者有没有办法摆脱这些讨厌的裂痕?

【问题讨论】:

  • 那是相当肮脏的撕裂。旋转轮本身的一种替代方法是将旋转量传递给填充圆圈上颜色的任何函数,然后相应地调整色轮,而无需进行变换。
  • 我现在无法重现您描述的问题。您可以尝试将 Graphics.PixelOffsetMode 设置为 PixelOffsetMode.Half。如果有帮助,请告诉我。
  • @aardvarkk 这听起来很有希望 - 我会看看其他选项。
  • @Lucas 刚试过这个,但没有任何改变。我什至尝试了“高质量”设置。没有骰子。

标签: c# graphics bitmap rotation gdi+


【解决方案1】:

查看该 Microsoft 示例的源代码,我通过添加矩阵并设置 RotateAt 方法对 UpdateDisplay 方法进行了以下更改。

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% 确定这是答案(但评论太长了),所以也许这会有所帮助。

【讨论】:

  • 我不知道为什么这样做会有所不同,但是现在翻录已经消失了。谢谢拉斯!
猜你喜欢
  • 2012-11-16
  • 2011-04-20
  • 2017-12-31
  • 2019-01-31
  • 2016-08-11
  • 2021-08-10
  • 2021-07-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多