本文整理汇总了C#中System.Drawing.Imaging.ImageAttributes.ClearColorKey方法的典型用法代码示例。如果您正苦于以下问题:C# ImageAttributes.ClearColorKey方法的具体用法?C# ImageAttributes.ClearColorKey怎么用?C# ImageAttributes.ClearColorKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Imaging.ImageAttributes
的用法示例。
在下文中一共展示了ImageAttributes.ClearColorKey方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDisabledImage
/// <summary>
/// Creates the disabled image for the specified Image
/// </summary>
/// <param name="normalImage"></param>
/// <returns></returns>
public static Image CreateDisabledImage(Image normalImage)
{
var imageAttr = new ImageAttributes();
imageAttr.ClearColorKey();
imageAttr.SetColorMatrix(DisabledImageColorMatrix);
var size = normalImage.Size;
var image = new Bitmap(size.Width, size.Height);
var graphics = Graphics.FromImage(image);
graphics.DrawImage(normalImage, new Rectangle(0, 0, size.Width, size.Height), 0, 0, size.Width, size.Height, GraphicsUnit.Pixel, imageAttr);
graphics.Dispose();
return image;
}
示例2: GetDesaturatedImageAttributes
/*
* GetDesaturatedImageAttributes
*/
/// <summary>
/// </summary>
/// <returns></returns>
public static ImageAttributes GetDesaturatedImageAttributes()
{
float[][] matrixComponents = new float[5][];
matrixComponents[0] = new float[] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f };
matrixComponents[1] = new float[] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f };
matrixComponents[2] = new float[] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f };
float[] transformComponents = new float[5];
transformComponents[3] = 1f;
matrixComponents[3] = transformComponents;
matrixComponents[4] = new float[] { 0.38f, 0.38f, 0.38f, 0f, 1f };
ImageAttributes imageAttributes = new ImageAttributes();
imageAttributes.ClearColorKey();
imageAttributes.SetColorMatrix(new ColorMatrix(matrixComponents));
return imageAttributes;
}
示例3: GetDisabledImage
public static Image GetDisabledImage(Image originalBitmap)
{
var disabledBitmap = new Bitmap(originalBitmap.Width, originalBitmap.Height);
var g = Graphics.FromImage(disabledBitmap);
// We create a color matrix to generated the disabled look
var array = new float[5][];
array[0] = new float[] { 0.2125f, 0.2125f, 0.2125f, 0, 0 };
array[1] = new float[] { 0.2577f, 0.2577f, 0.2577f, 0, 0 };
array[2] = new float[] { 0.0361f, 0.0361f, 0.0361f, 0, 0 };
array[3] = new float[] { 0, 0, 0, 1, 0 };
array[4] = new float[] { 0.38f, 0.38f, 0.38f, 0, 1 };
var grayMatrix = new ColorMatrix(array);
var disabledImageAttr = new ImageAttributes();
disabledImageAttr.ClearColorKey();
disabledImageAttr.SetColorMatrix(grayMatrix);
// We draw the image using the color matrix
var rectImage = new Rectangle(0, 0, originalBitmap.Width, originalBitmap.Height);
g.DrawImage(originalBitmap, rectImage, 0, 0, originalBitmap.Width, originalBitmap.Height, GraphicsUnit.Pixel, disabledImageAttr);
g.Dispose();
return disabledBitmap;
}
示例4: DrawImageDisabled
internal static void DrawImageDisabled(Graphics graphics, Image image, Rectangle imageBounds, Color background, bool unscaledImage)
{
if (graphics == null)
{
throw new ArgumentNullException("graphics");
}
if (image == null)
{
throw new ArgumentNullException("image");
}
Size size = image.Size;
if (disabledImageAttr == null)
{
float[][] newColorMatrix = new float[5][];
newColorMatrix[0] = new float[] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f };
newColorMatrix[1] = new float[] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f };
newColorMatrix[2] = new float[] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f };
float[] numArray2 = new float[5];
numArray2[3] = 1f;
newColorMatrix[3] = numArray2;
newColorMatrix[4] = new float[] { 0.38f, 0.38f, 0.38f, 0f, 1f };
ColorMatrix matrix = new ColorMatrix(newColorMatrix);
disabledImageAttr = new ImageAttributes();
disabledImageAttr.ClearColorKey();
disabledImageAttr.SetColorMatrix(matrix);
}
if (unscaledImage)
{
using (Bitmap bitmap = new Bitmap(image.Width, image.Height))
{
using (Graphics graphics2 = Graphics.FromImage(bitmap))
{
graphics2.DrawImage(image, new Rectangle(0, 0, size.Width, size.Height), 0, 0, size.Width, size.Height, GraphicsUnit.Pixel, disabledImageAttr);
}
graphics.DrawImageUnscaled(bitmap, imageBounds);
return;
}
}
graphics.DrawImage(image, imageBounds, 0, 0, size.Width, size.Height, GraphicsUnit.Pixel, disabledImageAttr);
}
示例5: CreateDisabledImage
/// <include file='doc\ToolStripRenderer.uex' path='docs/doc[@for="ToolStripRenderer.CreateDisabledImage"]/*' />
public static Image CreateDisabledImage(Image normalImage) {
ImageAttributes imgAttrib = new ImageAttributes();
imgAttrib.ClearColorKey();
imgAttrib.SetColorMatrix(DisabledImageColorMatrix);
Size size = normalImage.Size;
Bitmap disabledBitmap = new Bitmap(size.Width, size.Height);
Graphics graphics = Graphics.FromImage(disabledBitmap);
graphics.DrawImage(normalImage,
new Rectangle(0, 0, size.Width, size.Height),
0, 0, size.Width, size.Height,
GraphicsUnit.Pixel,
imgAttrib);
graphics.Dispose();
return disabledBitmap;
}
示例6: DrawAlphaImage
private void DrawAlphaImage(Image alphaImage, Image image, float percent)
{
float[][] newColorMatrix = new float[5][];
newColorMatrix[0] = new float[] { 1, 0, 0, 0, 0 };
newColorMatrix[1] = new float[] { 0, 1, 0, 0, 0 };
newColorMatrix[2] = new float[] { 0, 0, 1, 0, 0 };
newColorMatrix[3] = new float[] { 0, 0, 0, percent, 0 };
newColorMatrix[4] = new float[] { 0, 0, 0, 0, 1 };
ColorMatrix matrix = new ColorMatrix(newColorMatrix);
ImageAttributes imageAttributes = new ImageAttributes();
imageAttributes.ClearColorKey();
imageAttributes.SetColorMatrix(matrix);
using (Graphics gr = Graphics.FromImage(alphaImage))
{
gr.DrawImage(image, new Rectangle(0, 0, Size.Width, Size.Height), 0, 0, Size.Width, Size.Height, GraphicsUnit.Pixel, imageAttributes);
}
}
示例7: DrawForegroundFromButton
private void DrawForegroundFromButton(PaintEventArgs pevent)
{
if (_imageButton == null)
{
_imageButton = new Button();
_imageButton.Parent = new TransparentControl();
_imageButton.SuspendLayout();
_imageButton.BackColor = Color.Transparent;
_imageButton.FlatAppearance.BorderSize = 0;
_imageButton.FlatStyle = FlatStyle.Flat;
}
else
{
_imageButton.SuspendLayout();
}
_imageButton.AutoEllipsis = AutoEllipsis;
if (Enabled)
{
_imageButton.ForeColor = ForeColor;
}
else
{
_imageButton.ForeColor = Color.FromArgb((3*ForeColor.R + _backColor.R) >> 2,
(3*ForeColor.G + _backColor.G) >> 2,
(3*ForeColor.B + _backColor.B) >> 2);
}
_imageButton.Font = Font;
_imageButton.RightToLeft = RightToLeft;
_imageButton.Image = Image;
if (Image != null && !Enabled)
{
Size size = Image.Size;
var newColorMatrix = new float[5][];
newColorMatrix[0] = new[] {0.2125f, 0.2125f, 0.2125f, 0f, 0f};
newColorMatrix[1] = new[] {0.2577f, 0.2577f, 0.2577f, 0f, 0f};
newColorMatrix[2] = new[] {0.0361f, 0.0361f, 0.0361f, 0f, 0f};
var arr = new float[5];
arr[3] = 1f;
newColorMatrix[3] = arr;
newColorMatrix[4] = new[] {0.38f, 0.38f, 0.38f, 0f, 1f};
var matrix = new ColorMatrix(newColorMatrix);
var disabledImageAttr = new ImageAttributes();
disabledImageAttr.ClearColorKey();
disabledImageAttr.SetColorMatrix(matrix);
_imageButton.Image = new Bitmap(Image.Width, Image.Height);
using (Graphics gr = Graphics.FromImage(_imageButton.Image))
{
gr.DrawImage(Image, new Rectangle(0, 0, size.Width, size.Height), 0, 0, size.Width, size.Height,
GraphicsUnit.Pixel, disabledImageAttr);
}
}
_imageButton.ImageAlign = ImageAlign;
_imageButton.ImageIndex = ImageIndex;
_imageButton.ImageKey = ImageKey;
_imageButton.ImageList = ImageList;
_imageButton.Padding = Padding;
_imageButton.Size = Size;
_imageButton.Text = Text;
_imageButton.TextAlign = TextAlign;
_imageButton.TextImageRelation = TextImageRelation;
_imageButton.UseCompatibleTextRendering = UseCompatibleTextRendering;
_imageButton.UseMnemonic = UseMnemonic;
_imageButton.ResumeLayout();
InvokePaint(_imageButton, pevent);
if (_imageButton.Image != null && _imageButton.Image != Image)
{
_imageButton.Image.Dispose();
_imageButton.Image = null;
}
}
示例8: DrawImageDisabled
internal static void DrawImageDisabled(Graphics graphics, Image image, Rectangle imageBounds, Color background, bool unscaledImage) {
if (graphics == null) {
throw new ArgumentNullException("graphics");
}
if (image == null) {
throw new ArgumentNullException("image");
}
#if GRAYSCALE_DISABLED
Size imageSize = image.Size;
if (disabledImageAttr == null) {
// This is how I came up with this somewhat random ColorMatrix.
// Its set to resemble Office10 commandbars, but still be able to
// deal with hi-color (256+) icons and images.
//
// The idea is to scale everything down (more than just a grayscale does,
// therefore the small numbers in the scaling part of matrix)
// White -> some shade of gray &
// Black -> Black
//
// Second part of the matrix is to translate everything, so all colors are
// a bit brigher.
// Grays become lighter and washed out looking
// Black becomes a shade of gray as well.
//
// btw, if you do come up with something better let me know - [....]
float[][] array = new float[5][];
array[0] = new float[5] {0.2125f, 0.2125f, 0.2125f, 0, 0};
array[1] = new float[5] {0.2577f, 0.2577f, 0.2577f, 0, 0};
array[2] = new float[5] {0.0361f, 0.0361f, 0.0361f, 0, 0};
array[3] = new float[5] {0, 0, 0, 1, 0};
array[4] = new float[5] {0.38f, 0.38f, 0.38f, 0, 1};
ColorMatrix grayMatrix = new ColorMatrix(array);
disabledImageAttr = new ImageAttributes();
disabledImageAttr.ClearColorKey();
disabledImageAttr.SetColorMatrix(grayMatrix);
}
if (unscaledImage) {
using (Bitmap bmp = new Bitmap(image.Width, image.Height)) {
using (Graphics g = Graphics.FromImage(bmp)) {
g.DrawImage(image,
new Rectangle(0, 0, imageSize.Width, imageSize.Height),
0, 0, imageSize.Width, imageSize.Height,
GraphicsUnit.Pixel,
disabledImageAttr);
}
graphics.DrawImageUnscaled(bmp, imageBounds);
}
}
else {
graphics.DrawImage(image,
imageBounds,
0, 0, imageSize.Width, imageSize.Height,
GraphicsUnit.Pixel,
disabledImageAttr);
}
#else
// This is remarkably simple -- make a monochrome version of the image, draw once
// with the button highlight color, then a second time offset by one pixel
// and in the button shadow color.
// Technique borrowed from comctl Toolbar.
Bitmap bitmap;
bool disposeBitmap = false;
if (image is Bitmap)
bitmap = (Bitmap) image;
else {
// #37659 -- metafiles can have extremely high resolutions,
// so if we naively turn them into bitmaps, the performance will be very poor.
// bitmap = new Bitmap(image);
GraphicsUnit units = GraphicsUnit.Display;
RectangleF bounds = image.GetBounds(ref units);
bitmap = new Bitmap((int) (bounds.Width * graphics.DpiX / image.HorizontalResolution),
(int) (bounds.Height * graphics.DpiY / image.VerticalResolution));
Graphics bitmapGraphics = Graphics.FromImage(bitmap);
bitmapGraphics.Clear(Color.Transparent);
bitmapGraphics.DrawImage(image, 0, 0, image.Size.Width, image.Size.Height);
bitmapGraphics.Dispose();
disposeBitmap = true;
}
Color highlight = ControlPaint.LightLight(background);
Bitmap monochrome = MakeMonochrome(bitmap, highlight);
graphics.DrawImage(monochrome, new Rectangle(imageBounds.X + 1, imageBounds.Y + 1, imageBounds.Width, imageBounds.Height));
monochrome.Dispose();
Color shadow = ControlPaint.Dark(background);
monochrome = MakeMonochrome(bitmap, shadow);
graphics.DrawImage(monochrome, imageBounds);
monochrome.Dispose();
//.........这里部分代码省略.........
示例9: ImageMap
//=====================================================================
/// <summary>
/// Default constructor
/// </summary>
public ImageMap()
{
// Set the value of the double-buffering style bits to true
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);
this.UpdateStyles();
InitializeComponent();
gPanel = Graphics.FromHwnd(this.Handle);
activeArea = mouseArea = -1;
areaCursor = Cursors.Hand;
nonAreaCursor = Cursors.Default;
centerImage = true;
pathData = new GraphicsPath();
// Create the disabled image attributes on first use
if(iaDisabled == null)
{
float[][] afColorMatrix = new float[5][];
afColorMatrix[0] = new float[5] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f };
afColorMatrix[1] = new float[5] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f };
afColorMatrix[2] = new float[5] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f };
afColorMatrix[3] = new float[5] { 0f, 0f, 0f, 1f, 0f };
afColorMatrix[4] = new float[5] { 0.38f, 0.38f, 0.38f, 0f, 1f};
iaDisabled = new ImageAttributes();
iaDisabled.ClearColorKey();
iaDisabled.SetColorMatrix(new ColorMatrix(afColorMatrix));
}
}