本文整理汇总了C#中System.Windows.Media.Color.ToDrawingColor方法的典型用法代码示例。如果您正苦于以下问题:C# Color.ToDrawingColor方法的具体用法?C# Color.ToDrawingColor怎么用?C# Color.ToDrawingColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Color
的用法示例。
在下文中一共展示了Color.ToDrawingColor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBitmapFromBitmapSource
/// <summary>
/// Gets a System.Drawing.Bitmap from a BitmapSource.
/// </summary>
/// <param name="source">The source image from which to create our Bitmap.</param>
/// <param name="transparencyKey">The transparency key. This is used by the DragDropHelper
/// in rendering transparent pixels.</param>
/// <returns>An instance of Bitmap which is a copy of the BitmapSource's image.</returns>
private static Bitmap GetBitmapFromBitmapSource(BitmapSource source, Color transparencyKey)
{
// Copy at full size
Int32Rect sourceRect = new Int32Rect(0, 0, source.PixelWidth, source.PixelHeight);
// Convert to our destination pixel format
DrawingPixelFormat pxFormat = ConvertPixelFormat(source.Format);
// Create the Bitmap, full size, full rez
Bitmap bmp = new Bitmap(sourceRect.Width, sourceRect.Height, pxFormat);
// If the format is an indexed format, copy the color palette
if ((pxFormat & DrawingPixelFormat.Indexed) == DrawingPixelFormat.Indexed)
ConvertColorPalette(bmp.Palette, source.Palette);
// Get the transparency key as a System.Drawing.Color
DrawingColor transKey = transparencyKey.ToDrawingColor();
// Lock our Bitmap bits, we need to write to it
BitmapData bmpData = bmp.LockBits(
sourceRect.ToDrawingRectangle(),
ImageLockMode.ReadWrite,
pxFormat);
{
// Copy the source bitmap data to our new Bitmap
source.CopyPixels(sourceRect, bmpData.Scan0, bmpData.Stride * sourceRect.Height, bmpData.Stride);
// The drag image seems to work in full 32-bit color, except when
// alpha equals zero. Then it renders those pixels at black. So
// we make a pass and set all those pixels to the transparency key
// color. This is only implemented for 32-bit pixel colors for now.
if ((pxFormat & DrawingPixelFormat.Alpha) == DrawingPixelFormat.Alpha)
ReplaceTransparentPixelsWithTransparentKey(bmpData, transKey);
}
// Done, unlock the bits
bmp.UnlockBits(bmpData);
return bmp;
}