【发布时间】:2011-07-08 15:51:23
【问题描述】:
有一个以图像形式显示在图形视口中的指示器。指示器可以是用户选择的任何颜色,因此我们使用调色板创建了一个图像,并使用以下代码将调色板中的特定颜色更改为用户选择的颜色。
/// <summary>
/// Copies the image and sets transparency and fill colour of the copy. The image is intended to be a simple filled shape such as a square
/// with the inside all in one colour.
/// </summary>
/// <remarks>Assumes the fill colour to be changed is Red,
/// black is the boundary colour and off white (RGB 233,233,233) is the colour to be made transparent</remarks>
/// <param name="image"></param>
/// <param name="fillColour"></param>
/// <returns></returns>
protected Bitmap CopyWithStyle(Bitmap image, Color fillColour)
{
ColorPalette selectionIndicatorPalette = image.Palette;
int fillColourIndex = selectionIndicatorPalette.IndexOf(Color.Red);
selectionIndicatorPalette.Entries[fillColourIndex] = fillColour;
image.Palette = selectionIndicatorPalette;
Bitmap tempImage = image;
tempImage.MakeTransparent(transparentColour);
return tempImage;
}
说实话,我不确定这是否有点笨拙,是否有一些更聪明的方法,所以任何想法都会有所帮助。然而主要问题是这似乎在 Win7 上工作正常,但在 vista 和 XP 中颜色不会改变。有没有人见过这个。我发现一两篇文章表明它们之间的 ARGB 存在一些差异,但没有什么特别具体的。任何帮助都会被广泛接受。
【问题讨论】:
标签: c# .net windows-7 colors windows-vista