本文整理汇总了C#中System.Drawing.Graphics.GetNearestColor方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.GetNearestColor方法的具体用法?C# Graphics.GetNearestColor怎么用?C# Graphics.GetNearestColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Graphics
的用法示例。
在下文中一共展示了Graphics.GetNearestColor方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAlphaBlendedColor
private static Color GetAlphaBlendedColor(Graphics g, Color src, Color dest, int alpha)
{
int red = ((src.R * alpha) + ((0xff - alpha) * dest.R)) / 0xff;
int green = ((src.G * alpha) + ((0xff - alpha) * dest.G)) / 0xff;
int blue = ((src.B * alpha) + ((0xff - alpha) * dest.B)) / 0xff;
int num4 = ((src.A * alpha) + ((0xff - alpha) * dest.A)) / 0xff;
if (g == null)
{
return Color.FromArgb(num4, red, green, blue);
}
return g.GetNearestColor(Color.FromArgb(num4, red, green, blue));
}
示例2: GetAlphaBlendedColorHighRes
private static Color GetAlphaBlendedColorHighRes(Graphics graphics, Color src, Color dest, int alpha)
{
int num;
int num2;
int num6 = alpha;
if (num6 < 100)
{
num2 = 100 - num6;
num = 100;
}
else
{
num2 = 0x3e8 - num6;
num = 0x3e8;
}
int red = (((num6 * src.R) + (num2 * dest.R)) + (num / 2)) / num;
int green = (((num6 * src.G) + (num2 * dest.G)) + (num / 2)) / num;
int blue = (((num6 * src.B) + (num2 * dest.B)) + (num / 2)) / num;
if (graphics == null)
{
return Color.FromArgb(red, green, blue);
}
return graphics.GetNearestColor(Color.FromArgb(red, green, blue));
}
示例3: PaintPrivate
//.........这里部分代码省略.........
g.FillRectangle(SystemBrushes.Control, dropRect);
}
}
if (!paintFlat && !paintXPThemes && (drawComboBox || drawDropDownButton))
{
// border painting is ripped from button renderer
Color color= SystemColors.Control;
Color buttonShadow;
Color buttonShadowDark;
Color buttonFace = color;
Color highlight;
bool stockColor = color.ToKnownColor() == SystemColors.Control.ToKnownColor();
bool highContrast = SystemInformation.HighContrast;
if (color == SystemColors.Control)
{
buttonShadow = SystemColors.ControlDark;
buttonShadowDark = SystemColors.ControlDarkDark;
highlight = SystemColors.ControlLightLight;
}
else
{
buttonShadow = ControlPaint.Dark(color);
highlight = ControlPaint.LightLight(color);
if (highContrast)
{
buttonShadowDark = ControlPaint.LightLight(color);
}
else
{
buttonShadowDark = ControlPaint.DarkDark(color);
}
}
buttonShadow = g.GetNearestColor(buttonShadow);
buttonShadowDark = g.GetNearestColor(buttonShadowDark);
buttonFace = g.GetNearestColor(buttonFace);
highlight = g.GetNearestColor(highlight);
// top + left
Pen pen;
if (stockColor) {
if (SystemInformation.HighContrast) {
pen = SystemPens.ControlLight;
}
else {
pen = SystemPens.Control;
}
}
else {
pen= new Pen(highlight);
}
if (drawDropDownButton)
{
g.DrawLine(pen, dropRect.X, dropRect.Y,
dropRect.X + dropRect.Width - 1, dropRect.Y);
g.DrawLine(pen, dropRect.X, dropRect.Y,
dropRect.X, dropRect.Y + dropRect.Height - 1);
}
// the bounds around the combobox control
if (drawComboBox)
{
g.DrawLine(pen, valBounds.X, valBounds.Y + valBounds.Height - 1,
valBounds.X + valBounds.Width - 1, valBounds.Y + valBounds.Height - 1);
g.DrawLine(pen, valBounds.X + valBounds.Width - 1, valBounds.Y,
valBounds.X + valBounds.Width - 1, valBounds.Y + valBounds.Height - 1);
}
示例4: GetSelectedItemWithFocusBackBrush
public virtual Brush GetSelectedItemWithFocusBackBrush(Graphics g)
{
if (ownerGrid.selectedItemWithFocusBackBrush == null) {
Color clr = g.GetNearestColor(ownerGrid.SelectedItemWithFocusBackColor);
ownerGrid.selectedItemWithFocusBackBrush = new SolidBrush(clr);
}
return ownerGrid.selectedItemWithFocusBackBrush;
}
示例5: GetLineBrush
public virtual Brush GetLineBrush(Graphics g) {
if (ownerGrid.lineBrush == null) {
Color clr = g.GetNearestColor(ownerGrid.LineColor);
ownerGrid.lineBrush = new SolidBrush(clr);
}
return ownerGrid.lineBrush;
}
示例6: PaintLabel
public virtual void PaintLabel(Graphics g, Rectangle rect, Rectangle clipRect, bool selected, bool paintFullLabel)
{
PropertyGridView gridEntryHost = this.GridEntryHost;
string propertyLabel = this.PropertyLabel;
int width = gridEntryHost.GetOutlineIconSize() + 5;
Brush brush = selected ? SystemBrushes.Highlight : this.GetBackgroundBrush(g);
if (selected && !this.hasFocus)
{
brush = gridEntryHost.GetLineBrush(g);
}
bool boldFont = (this.Flags & 0x40) != 0;
Font f = this.GetFont(boldFont);
int num2 = this.GetLabelTextWidth(propertyLabel, g, f);
int num3 = paintFullLabel ? num2 : 0;
int x = rect.X + this.PropertyLabelIndent;
Brush brush2 = brush;
if (paintFullLabel && (num3 >= (rect.Width - (x + 2))))
{
int num5 = (x + num3) + 2;
g.FillRectangle(brush2, width - 1, rect.Y, (num5 - width) + 3, rect.Height);
Pen pen = new Pen(gridEntryHost.GetLineColor());
g.DrawLine(pen, num5, rect.Y, num5, rect.Height);
pen.Dispose();
rect.Width = num5 - rect.X;
}
else
{
g.FillRectangle(brush2, rect.X, rect.Y, rect.Width, rect.Height);
}
Brush lineBrush = gridEntryHost.GetLineBrush(g);
g.FillRectangle(lineBrush, rect.X, rect.Y, width, rect.Height);
if (selected && this.hasFocus)
{
g.FillRectangle(SystemBrushes.Highlight, x, rect.Y, (rect.Width - x) - 1, rect.Height);
}
int num6 = Math.Min((int) ((rect.Width - x) - 1), (int) (num2 + 2));
Rectangle a = new Rectangle(x, rect.Y + 1, num6, rect.Height - 1);
if (Rectangle.Intersect(a, clipRect).IsEmpty)
{
goto Label_0292;
}
Region clip = g.Clip;
g.SetClip(a);
Color color = (selected && this.hasFocus) ? SystemColors.HighlightText : g.GetNearestColor(this.LabelTextColor);
if (this.ownerGrid.UseCompatibleTextRendering)
{
using (Brush brush4 = new SolidBrush(color))
{
StringFormat format = new StringFormat(StringFormatFlags.NoWrap) {
Trimming = StringTrimming.None
};
g.DrawString(propertyLabel, f, brush4, a, format);
goto Label_0257;
}
}
TextRenderer.DrawText(g, propertyLabel, f, a, color, PropertyGrid.MeasureTextHelper.GetTextRendererFlags());
Label_0257:
g.SetClip(clip, CombineMode.Replace);
clip.Dispose();
if (num6 <= num2)
{
this.labelTipPoint = new Point(x + 2, rect.Y + 1);
}
else
{
this.labelTipPoint = InvalidPoint;
}
Label_0292:
rect.Y--;
rect.Height += 2;
this.PaintOutline(g, rect);
}
示例7: GetLineBrush
public virtual Brush GetLineBrush(Graphics g)
{
if (this.ownerGrid.lineBrush == null)
{
System.Drawing.Color nearestColor = g.GetNearestColor(this.ownerGrid.LineColor);
this.ownerGrid.lineBrush = new SolidBrush(nearestColor);
}
return this.ownerGrid.lineBrush;
}
示例8: PaintPrivate
//.........这里部分代码省略.........
resultBounds = new Rectangle(checkBoxX, checkBoxY, checkBoxSize.Width, checkBoxSize.Height);
}
else if (this.FlatStyle == FlatStyle.Flat)
{
// CheckBox::Paint will only paint the check box differently when in FlatStyle.Flat
// this code is copied from CheckBox::DrawCheckFlat. it was a lot of trouble making this function static
Rectangle checkBounds = new Rectangle(checkBoxX, checkBoxY, checkBoxSize.Width, checkBoxSize.Height);
SolidBrush foreBrush = null;
SolidBrush backBrush = null;
Color highlight = Color.Empty;
if (paint && DataGridViewCell.PaintContentForeground(paintParts))
{
foreBrush = this.DataGridView.GetCachedBrush(cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor);
backBrush = this.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor);
highlight = ControlPaint.LightLight(backBrush.Color);
if (this.DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex &&
mouseInContentBounds)
{
const float lowlight = .1f;
float adjust = 1 - lowlight;
if (highlight.GetBrightness() < .5)
{
adjust = 1 + lowlight * 2;
}
highlight = Color.FromArgb(ButtonInternal.ButtonBaseAdapter.ColorOptions.Adjust255(adjust, highlight.R),
ButtonInternal.ButtonBaseAdapter.ColorOptions.Adjust255(adjust, highlight.G),
ButtonInternal.ButtonBaseAdapter.ColorOptions.Adjust255(adjust, highlight.B));
}
highlight = g.GetNearestColor(highlight);
using (Pen pen = new Pen(foreBrush.Color))
{
g.DrawLine(pen, checkBounds.Left, checkBounds.Top, checkBounds.Right-1, checkBounds.Top);
g.DrawLine(pen, checkBounds.Left, checkBounds.Top, checkBounds.Left, checkBounds.Bottom-1);
}
}
checkBounds.Inflate(-1, -1);
checkBounds.Width++;
checkBounds.Height++;
if (paint && DataGridViewCell.PaintContentForeground(paintParts))
{
if (checkState == CheckState.Indeterminate)
{
ButtonInternal.ButtonBaseAdapter.DrawDitheredFill(g, backBrush.Color, highlight, checkBounds);
}
else
{
using (SolidBrush highBrush = new SolidBrush(highlight))
{
g.FillRectangle(highBrush, checkBounds);
}
}
// draw the check box
if (checkState != CheckState.Unchecked)
{
Rectangle fullSize = new Rectangle(checkBoxX-1, checkBoxY-1, checkBoxSize.Width+3, checkBoxSize.Height+3);
fullSize.Width++;
fullSize.Height++;
示例9: GetAlphaBlendedColorHighRes
private static Color GetAlphaBlendedColorHighRes(Graphics graphics, Color src, Color dest, int alpha)
{
int factor = 100;
int inv_alpha = 100 - alpha;
if (alpha >= 100)
{
inv_alpha = 1000 - alpha;
factor = 1000;
}
int r = (((alpha * src.R) + (inv_alpha * dest.R)) + (factor / 2)) / factor;
int g = (((alpha * src.G) + (inv_alpha * dest.G)) + (factor / 2)) / factor;
int b = (((alpha * src.B) + (inv_alpha * dest.B)) + (factor / 2)) / factor;
if (graphics == null) return Color.FromArgb(r, g, b);
else return graphics.GetNearestColor(Color.FromArgb(r, g, b));
}
示例10: GetAlphaBlendedColor
private static Color GetAlphaBlendedColor(Graphics graphics, Color src, Color dest, int alpha)
{
int r = ((src.R * alpha) + ((255 - alpha) * dest.R)) / 255;
int g = ((src.G * alpha) + ((255 - alpha) * dest.G)) / 255;
int b = ((src.B * alpha) + ((255 - alpha) * dest.B)) / 255;
int a = ((src.A * alpha) + ((255 - alpha) * dest.A)) / 255;
if (graphics == null) return Color.FromArgb(a, r, g, b);
else return graphics.GetNearestColor(Color.FromArgb(a, r, g, b));
}
示例11: GetAlphaBlendedColorHighRes
// this particular method gets us closer to office by increasing the resolution...
private static Color GetAlphaBlendedColorHighRes(Graphics graphics, Color src, Color dest, int alpha) {
int sum;
int nPart2;
int r, g, b;
int nPart1 = alpha;
if (nPart1 < 100) {
nPart2 = 100 - nPart1;
sum = 100;
}
else {
nPart2 = 1000 - nPart1;
sum = 1000;
}
// By adding on sum/2 before dividing by sum, we properly round the value,
// rather than truncating it, while doing integer math.
r = (nPart1 * src.R + nPart2 * dest.R + sum / 2) / sum;
g = (nPart1 * src.G + nPart2 * dest.G + sum / 2) / sum;
b = (nPart1 * src.B + nPart2 * dest.B + sum / 2) / sum;
if (graphics == null) {
return Color.FromArgb(r, g, b);
}
else {
return graphics.GetNearestColor(Color.FromArgb(r, g, b));
}
}
示例12: FromKnownColor
/* public virtual Color ControlLight {
get { return FromKnownColor(KnownColors.msocbvcrCBCtlBkgdLight); }
} */
private static Color GetAlphaBlendedColor(Graphics g, Color src, Color dest, int alpha) {
int red = (src.R * alpha + (255 - alpha) * dest.R) / 255;
int green = (src.G * alpha + (255 - alpha) * dest.G) / 255;
int blue = (src.B * alpha + (255 - alpha) * dest.B) / 255;
int newAlpha = (src.A * alpha + (255 - alpha) * dest.A) / 255;
if (g == null) {
return Color.FromArgb(newAlpha, red, green, blue);
}
else {
return g.GetNearestColor(Color.FromArgb(newAlpha, red, green, blue));
}
}
示例13: PaintPrivate
//.........这里部分代码省略.........
if (paint && DataGridViewCell.PaintContentForeground(paintParts))
{
if (isMixed)
{
ControlPaint.DrawMixedCheckBox(g, x, y, glyphSize.Width, glyphSize.Height, normal);
}
else
{
ControlPaint.DrawCheckBox(g, x, y, glyphSize.Width, glyphSize.Height, normal);
}
}
checkBounds = new Rectangle(x, y, glyphSize.Width, glyphSize.Height);
}
else if (this.FlatStyle == System.Windows.Forms.FlatStyle.Flat)
{
Rectangle bounds = new Rectangle(x, y, glyphSize.Width, glyphSize.Height);
SolidBrush brush2 = null;
SolidBrush brush3 = null;
Color empty = Color.Empty;
if (paint && DataGridViewCell.PaintContentForeground(paintParts))
{
brush2 = base.DataGridView.GetCachedBrush(flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor);
brush3 = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor);
empty = ControlPaint.LightLight(brush3.Color);
if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds)
{
float percentage = 0.9f;
if (empty.GetBrightness() < 0.5)
{
percentage = 1.2f;
}
empty = Color.FromArgb(ButtonBaseAdapter.ColorOptions.Adjust255(percentage, empty.R), ButtonBaseAdapter.ColorOptions.Adjust255(percentage, empty.G), ButtonBaseAdapter.ColorOptions.Adjust255(percentage, empty.B));
}
empty = g.GetNearestColor(empty);
using (Pen pen = new Pen(brush2.Color))
{
g.DrawLine(pen, bounds.Left, bounds.Top, bounds.Right - 1, bounds.Top);
g.DrawLine(pen, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 1);
}
}
bounds.Inflate(-1, -1);
bounds.Width++;
bounds.Height++;
if (paint && DataGridViewCell.PaintContentForeground(paintParts))
{
if (@unchecked == CheckState.Indeterminate)
{
ButtonBaseAdapter.DrawDitheredFill(g, brush3.Color, empty, bounds);
}
else
{
using (SolidBrush brush4 = new SolidBrush(empty))
{
g.FillRectangle(brush4, bounds);
}
}
if (@unchecked != CheckState.Unchecked)
{
Rectangle destination = new Rectangle(x - 1, y - 1, glyphSize.Width + 3, glyphSize.Height + 3);
destination.Width++;
destination.Height++;
if (((checkImage == null) || (checkImage.Width != destination.Width)) || (checkImage.Height != destination.Height))
{
if (checkImage != null)
{
checkImage.Dispose();