当前位置: 首页>>代码示例>>C#>>正文


C# Media.PixelFormat类代码示例

本文整理汇总了C#中System.Windows.Media.PixelFormat的典型用法代码示例。如果您正苦于以下问题:C# PixelFormat类的具体用法?C# PixelFormat怎么用?C# PixelFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PixelFormat类属于System.Windows.Media命名空间,在下文中一共展示了PixelFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToBitmap

        /// <summary>
        /// Converts a depth frame to the corresponding System.Windows.Media.ImageSource.
        /// </summary>
        /// <param name="frame">The specified depth frame.</param>
        /// <param name="format">Pixel format of the depth frame.</param>
        /// <param name="mode">Depth frame mode.</param>
        /// <returns>The corresponding System.Windows.Media.ImageSource representation of the depth frame.</returns>
        public static ImageSource ToBitmap(this DepthImageFrame frame, PixelFormat format, DepthImageMode mode)
        {
            short[] pixelData = new short[frame.PixelDataLength];
            frame.CopyPixelDataTo(pixelData);

            byte[] pixels;

            switch (mode)
            {
                case DepthImageMode.Raw:
                    pixels = GenerateRawFrame(frame, pixelData);
                    break;
                case DepthImageMode.Dark:
                    pixels = GenerateDarkFrame(frame, pixelData);
                    break;
                case DepthImageMode.Colors:
                    pixels = GenerateColoredFrame(frame, pixelData);
                    break;
                case DepthImageMode.Player:
                    pixels = GeneratePlayerFrame(frame, pixelData);
                    break;
                default:
                    pixels = GenerateRawFrame(frame, pixelData);
                    break;
            }

            return pixels.ToBitmap(frame.Width, frame.Height, format);
        }
开发者ID:kmbraswe,项目名称:Vitruvius,代码行数:35,代码来源:DepthExtensions.cs

示例2: ToBitmapSource

        /// <summary>
        /// MatをBitmapSourceに変換する. 
        /// </summary>
        /// <param name="src">変換するIplImage</param>
        /// <param name="horizontalResolution"></param>
        /// <param name="verticalResolution"></param>
        /// <param name="pixelFormat"></param>
        /// <param name="palette"></param>
        /// <returns>WPFのBitmapSource</returns>
#else
        /// <summary>
        /// Converts Mat to BitmapSource.
        /// </summary>
        /// <param name="src">Input IplImage</param>
        /// <param name="horizontalResolution"></param>
        /// <param name="verticalResolution"></param>
        /// <param name="pixelFormat"></param>
        /// <param name="palette"></param>
        /// <returns>BitmapSource</returns>
#endif
        public static BitmapSource ToBitmapSource(
            this Mat src,
            int horizontalResolution,
            int verticalResolution,
            PixelFormat pixelFormat,
            BitmapPalette palette)
        {
            if (src == null)
                throw new ArgumentNullException("src");
            if (src.IsDisposed)
                throw new ObjectDisposedException(typeof(Mat).ToString());
            if (src.Dims() != 2)
                throw new ArgumentException("src.Dims() != 2");

            long step = src.Step();
            return BitmapSource.Create(
                src.Width,
                src.Height,
                horizontalResolution,
                verticalResolution,
                pixelFormat,
                palette,
                src.Data,
                (int)(step * src.Rows),
                (int)step);
        }
开发者ID:rblenis,项目名称:opencvsharp,代码行数:46,代码来源:BitmapSourceConverter.cs

示例3: RenderToBitmap

        /// <summary>
        /// 
        /// </summary>
        /// <param name="geometry"></param>
        /// <param name="bitmapSize"></param>
        /// <param name="geometryPositionOnBitmap"></param>
        /// <param name="brush">The Brush with which to fill the Geometry. This is optional, and can be null. If the brush is null, no fill is drawn.</param>
        /// <param name="pen">The Pen with which to stroke the Geometry. This is optional, and can be null. If the pen is null, no stroke is drawn</param>
        /// <param name="pixelFormat"></param>
        /// <param name="dpiX"></param>
        /// <param name="dpiY"></param>
        /// <returns></returns>
        public static BitmapSource RenderToBitmap(
            this Geometry geometry,
            Size bitmapSize,
            Point geometryPositionOnBitmap,
            Size geometrySize,
            Brush brush,
            Pen pen,
            PixelFormat pixelFormat,
            double dpiX = 96.0,
            double dpiY = 96.0)
        {
            var rtb = new RenderTargetBitmap((int)(bitmapSize.Width * dpiX / 96.0),
                                             (int)(bitmapSize.Height * dpiY / 96.0),
                                             dpiX,
                                             dpiY,
                                             pixelFormat);

            var dv = new DrawingVisual();

            using (var cx = dv.RenderOpen())
            {
                cx.Render(geometry, geometryPositionOnBitmap, brush, pen);
            }

            rtb.Render(dv);

            return rtb;
        }
开发者ID:squaredinfinity,项目名称:Foundation,代码行数:40,代码来源:Geometry.extensions.cs

示例4: RenderToBitmap

        public static BitmapSource RenderToBitmap(
            this Visual visual,
            PixelFormat pixelFormat,
            FlowDirection flowDirection = FlowDirection.LeftToRight,
            double dpiX = 96.0,
            double dpiY = 96.0)
        {
            if (visual == null)
                throw new ArgumentException("visual");

            var cv = visual as ContainerVisual;
            if (cv != null)
            {
                var bounds = cv.DescendantBounds;

                var size = new Size(bounds.Right, bounds.Bottom);

                return visual.RenderToBitmap(size, bounds.Location, bounds.Size, pixelFormat);
            }
            else
            {
                var bounds = VisualTreeHelper.GetDescendantBounds(visual);

                var size = new Size(bounds.Right, bounds.Bottom);

                return visual.RenderToBitmap(size, bounds.Location, bounds.Size, pixelFormat);
            }
        }
开发者ID:squaredinfinity,项目名称:Foundation,代码行数:28,代码来源:Visual.extensions.cs

示例5: BitmapSourceConverter

        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="format">The pixel format to use for conversion.</param>
        /// <param name="encoder">The encoder to use.</param>
        /// <param name="rotate">Degrees of rotation to apply (counterclock whise).</param>
        public BitmapSourceConverter(PixelFormat format, Encoder encoder, int rotate = 0)
        {
            _format = format;
            _encoder = encoder;

            Rotate = rotate;
        }
开发者ID:skpdvdd,项目名称:Pdf2KT,代码行数:13,代码来源:BitmapSourceConverter.cs

示例6: GetPixels

 public static IEnumerable<ColorRGBA> GetPixels(byte[] pixelByteArray, PixelFormat pixelFormat)
 {
     if (pixelFormat == PixelFormats.Bgra32)
     {
         for (int i = 0; i < pixelByteArray.Length; i += 4)
         {
             yield return new ColorRGBA
             {
                 Blue = pixelByteArray[i],
                 Green = pixelByteArray[i + 1],
                 Red = pixelByteArray[i + 2],
                 Alpha = pixelByteArray[i + 3]
             };
         }
     }
     else if (pixelFormat == PixelFormats.Bgr32)
     {
         for (int i = 0; i < pixelByteArray.Length; i += 4)
         {
             yield return new ColorRGBA
             {
                 Blue = pixelByteArray[i],
                 Green = pixelByteArray[i + 1],
                 Red = pixelByteArray[i + 2],
                 Alpha = 255
             };
         }
     }
     else
     {
         yield break;
     }
 }
开发者ID:AndrewShepherd,项目名称:Drawception-Helper,代码行数:33,代码来源:BitmapUtils.cs

示例7: ColorConvertedBitmap

        /// <summary> 
        /// Construct a ColorConvertedBitmap
        /// </summary>
        /// <param name="source">Input BitmapSource to color convert</param>
        /// <param name="sourceColorContext">Source Color Context</param> 
        /// <param name="destinationColorContext">Destination Color Context</param>
        /// <param name="format">Destination Pixel format</param> 
        public ColorConvertedBitmap(BitmapSource source, ColorContext sourceColorContext, ColorContext destinationColorContext, PixelFormat format) 
            : base(true) // Use base class virtuals
        { 
            if (source == null)
            {
                throw new ArgumentNullException("source");
            } 

            if (sourceColorContext == null) 
            { 
                throw new ArgumentNullException("sourceColorContext");
            } 

            if (destinationColorContext == null)
            {
                throw new ArgumentNullException("destinationColorContext"); 
            }
 
            _bitmapInit.BeginInit(); 

            Source = source; 
            SourceColorContext = sourceColorContext;
            DestinationColorContext = destinationColorContext;
            DestinationFormat = format;
 
            _bitmapInit.EndInit();
            FinalizeCreation(); 
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:35,代码来源:ColorConvertedBitmap.cs

示例8: ConvertTo

 /// <summary>
 /// Конвертация BitmapSource в другой формат BitmapSource.
 /// </summary>
 /// <param name="source">Источник для конвертации.</param>
 /// <param name="destinationFormat">Новый формат.</param>
 /// <param name="destinationPalette">
 /// Палитра для нового формата, если конечно она нужна для нового формата, иначе передать null.
 /// </param>
 /// <returns>BitmapSource в новом формате.</returns>
 public static BitmapSource ConvertTo(
     this BitmapSource source,
     PixelFormat destinationFormat,
     BitmapPalette destinationPalette)
 {
     return new FormatConvertedBitmap(
         source, destinationFormat, destinationPalette, 0);
 }
开发者ID:wegorich,项目名称:UltimateCommander-WPF-file-Manager,代码行数:17,代码来源:Converter.cs

示例9: GetConverter

        public static IBitmapSourceGrayScaleConverter GetConverter(PixelFormat format)
        {
            if (format == PixelFormats.Bgra32 || format == PixelFormats.Bgr32)
                return BgrGrayScaleConverter.Instance;


            throw new NotSupportedException(string.Format("PixelFormat {0} is not supported", format.GetType().Name));
        }
开发者ID:CallWall,项目名称:CallWall.Windows,代码行数:8,代码来源:GrayScaleConverter.cs

示例10: MapUpdatedEventArgs

 public MapUpdatedEventArgs(byte[] map, int xres, int yres, int stride, PixelFormat format)
 {
     this.Map = map;
     this.XRes = xres;
     this.YRes = yres;
     this.Stride = stride;
     this.Format = format;
 }
开发者ID:InfoStrat,项目名称:MotionFx,代码行数:8,代码来源:MapUpdatedEventArgs.cs

示例11: RenderedBitmap

 public RenderedBitmap(int width, int height, int stride, PixelFormat format, byte[] bits)
 {
     this.width = width;
       this.height = height;
       this.stride = stride;
       this.format = format;
       this.bits = bits;
 }
开发者ID:ewrogers,项目名称:SleepHunter4,代码行数:8,代码来源:RenderedBitmap.cs

示例12: ImageContext

 public ImageContext(int h, int w, PixelFormat f)
 {
     Height = h;
     Width = w;
     ImageFormat = f;
     NStride = (Width * ImageFormat.BitsPerPixel + 7) / 8;
     PixelByteArraySize = Height * NStride;
     PixelByteArray = new byte[PixelByteArraySize];
 }
开发者ID:PokrovskiyEgor,项目名称:ForImg2,代码行数:9,代码来源:ImageContext.cs

示例13: ConvertToOtherPixelFormat

 public static BitmapImage ConvertToOtherPixelFormat(BitmapSource source, PixelFormat format)
 {
     var newFormatedBitmapSource = new FormatConvertedBitmap();
     newFormatedBitmapSource.BeginInit();
     newFormatedBitmapSource.Source = source;
     newFormatedBitmapSource.DestinationFormat = format;
     newFormatedBitmapSource.EndInit();
     return BitmapSourceToBitmapImage(newFormatedBitmapSource.Source);
 }
开发者ID:kib357,项目名称:Ester2,代码行数:9,代码来源:WorkWithImages.cs

示例14: CaptureSnapshot

 /// <summary>Captures a snapshot of the source element as a bitmap image. The snapshot is created based on the specified rendering parameters.</summary>
 /// <param name="sourceElement">The source element.</param>
 /// <param name="bitmapSize">The bitmap size.</param>
 /// <param name="scalingMode">The bitmap scaling mode.</param>
 /// <param name="bitmapDpi">The bitmap dpi.</param>
 /// <param name="pixelFormat">The bitmap pixel format.</param>
 /// <returns>The snapshot of the source element.</returns>
 public static BitmapSource CaptureSnapshot(FrameworkElement sourceElement, Size bitmapSize, BitmapScalingMode scalingMode, Vector bitmapDpi, PixelFormat pixelFormat) {
    if (sourceElement == null || bitmapSize.IsZero()) return null;
    var snapshot = new RenderTargetBitmap((int)bitmapSize.Width, (int)bitmapSize.Height, bitmapDpi.X, bitmapDpi.Y, pixelFormat);
    sourceElement.SetValue(RenderOptions.BitmapScalingModeProperty, scalingMode);
    snapshot.Render(sourceElement);
    sourceElement.ClearValue(RenderOptions.BitmapScalingModeProperty);
    snapshot.Freeze();
    return snapshot;
 }
开发者ID:borkaborka,项目名称:gmit,代码行数:16,代码来源:ImageServices.cs

示例15: ToBitmap

 public static Bitmap ToBitmap(this DepthImageFrame image, PixelFormat format)
 {
     if (image == null || image.PixelDataLength == 0)
         return null;
     var data = new short[image.PixelDataLength];
     image.CopyPixelDataTo(data);
     return data.ToBitmap(image.Width, image.Height
         , format);
 }
开发者ID:playboy210,项目名称:playboy,代码行数:9,代码来源:ImageExtensions.cs


注:本文中的System.Windows.Media.PixelFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。