2012-02-02 62 views
3

我正在執行seminal article中描述的顏色選擇器組件。我可以在沒有這些工件的情況下使用graphics.RotateTransform()嗎?

正如你所看到的,我已經掌握了一些基本排序:

Working colour wheel

一個不過的要求,就是要有任意量旋轉的色輪的能力。認爲這是容易的,我的一些算術鼠標位置 - >色值代碼和下面的代碼位,實際上油漆輪:

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

不幸的是,旋轉這樣的位圖實際上產生這樣的:

Broken colour wheel after rotation

請注意出現在中心兩側的文物。

我使用了錯誤的方法嗎?或者有沒有辦法擺脫這些討厭的撕裂?

+1

這是一些非常髒的撕裂。旋轉輪本身的一種替代方法是將旋轉量傳遞給填充圓上顏色的任何函數,然後相應地調整色輪而不需要進行變換。 – aardvarkk 2012-02-02 18:34:45

+0

我無法重新創建您現在描述的問題。您可以嘗試將Graphics.PixelOffsetMode設置爲PixelOffsetMode.Half。讓我知道它是否有幫助。 – 2012-02-02 19:35:08

+0

@aardvarkk這聽起來很有希望 - 我會看看其他選項。 – 2012-02-02 22:56:20

回答

3

查看該示例的源代碼,我對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

相關問題