Example #1
0
 /// <summary>
 /// Selects the pixel format.
 /// </summary>
 /// <param name="pixelFormat">The pixel format.</param>
 /// <returns></returns>
 /// <exception cref="ArgumentException">Wrong pixel format " + pixelFormat.ToString()</exception>
 private static PixelFormat SelectPixelFormat(SysMedia.PixelFormat pixelFormat)
 {
     if (SysMedia.PixelFormats.Bgra32 == pixelFormat)
     {
         return(PixelFormat.Bgra);
     }
     else if (SysMedia.PixelFormats.Rgb24 == pixelFormat)
     {
         return(PixelFormat.Bgr);
     }
     else if (SysMedia.PixelFormats.Gray8 == pixelFormat)
     {
         return(PixelFormat.Red);
     }
     else
     {
         throw new ArgumentException("Wrong pixel format " + pixelFormat.ToString());
     }
 }
 /// <summary>
 /// Determines if alpha channel COULD be present in given format.
 /// </summary>
 /// <param name="format">Format to check alpha in.</param>
 /// <returns>True if alpha can be present.</returns>
 public static bool IsAlphaPresent(PixelFormat format)
 {
     return format.ToString().Contains("a", StringComparison.OrdinalIgnoreCase);
 }
        public static System.Drawing.Imaging.PixelFormat Convert(this System.Windows.Media.PixelFormat pixelFormat)
        {
            if (pixelFormat == System.Windows.Media.PixelFormats.Gray16)
            {
                return(System.Drawing.Imaging.PixelFormat.Format16bppGrayScale);
            }
            if (pixelFormat == System.Windows.Media.PixelFormats.Bgr555)
            {
                return(System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
            }
            if (pixelFormat == System.Windows.Media.PixelFormats.Bgr565)
            {
                return(System.Drawing.Imaging.PixelFormat.Format16bppRgb565);
            }

            if (pixelFormat == System.Windows.Media.PixelFormats.Bgr101010)
            {
                return(System.Drawing.Imaging.PixelFormat.Indexed);
            }
            if (pixelFormat == System.Windows.Media.PixelFormats.Indexed1)
            {
                return(System.Drawing.Imaging.PixelFormat.Format1bppIndexed);
            }
            if (pixelFormat == System.Windows.Media.PixelFormats.Indexed4)
            {
                return(System.Drawing.Imaging.PixelFormat.Format4bppIndexed);
            }
            if (pixelFormat == System.Windows.Media.PixelFormats.Indexed8)
            {
                return(System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
            }

            //if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format16bppArgb1555)
            //    return System.Windows.Media.PixelFormats.Bgr101010;

            if (pixelFormat == System.Windows.Media.PixelFormats.Bgr24)
            {
                return(System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            }

            if (pixelFormat == System.Windows.Media.PixelFormats.Bgr32)
            {
                return(System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            }
            if (pixelFormat == System.Windows.Media.PixelFormats.Pbgra32)
            {
                return(System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            }
            if (pixelFormat == System.Windows.Media.PixelFormats.Bgr32)
            {
                return(System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            }

            if (pixelFormat == System.Windows.Media.PixelFormats.Rgb48)
            {
                return(System.Drawing.Imaging.PixelFormat.Format48bppRgb);
            }

            if (pixelFormat == System.Windows.Media.PixelFormats.Prgba64)
            {
                return(System.Drawing.Imaging.PixelFormat.Format64bppArgb);
            }

            // TODO :
            //if (pixelFormat == System.Windows.Media.PixelFormats.)
            //    return System.Drawing.Imaging.PixelFormat.Alpha;
            //if (pixelFormat == System.Windows.Media.PixelFormats.)
            //    return System.Drawing.Imaging.PixelFormat.Canonical;
            //if (pixelFormat == System.Windows.Media.PixelFormats.)
            //    return System.Drawing.Imaging.PixelFormat.DontCare;
            //    return System.Windows.Media.PixelFormats.;
            //if (pixelFormat == System.Windows.Media.PixelFormats.)
            //    return System.Drawing.Imaging.PixelFormat.Extended;
            //if (pixelFormat == System.Windows.Media.PixelFormats.)
            //    return System.Drawing.Imaging.PixelFormat.Gdi;
            //if (pixelFormat == System.Windows.Media.PixelFormats.)
            //    return System.Drawing.Imaging.PixelFormat.Max;
            //if (pixelFormat == System.Windows.Media.PixelFormats.)
            //    return System.Drawing.Imaging.PixelFormat.PAlpha;
            //if (pixelFormat == System.Windows.Media.PixelFormats.)
            //    return System.Drawing.Imaging.PixelFormat.Undefined;

            if (pixelFormat == System.Windows.Media.PixelFormats.Default)
            {
                return(System.Drawing.Imaging.PixelFormat.Undefined);
            }

            throw new NotSupportedException("Convertion not supported with " + pixelFormat.ToString());
        }