Example #1
0
        public static ByteImage ToByteImageOfY(this RawBitmapData rawBitmapData, Rectangle area)
        {
            RawBitmapData rawBitmapData1ByteComponent = rawBitmapData;

            if (!Is1BytePerComponentFormat(rawBitmapData.PixelFormat))
            {
                using (var bitmap = rawBitmapData.ToBitmap())
                {
                    if (bitmap.PixelFormat == PixelFormat.Format24bppRgb)
                    {
                        rawBitmapData1ByteComponent = bitmap.ToRawBitmapData();
                    }
                    else
                    {
                        using (var bitmap24Rgb = bitmap.ToRgb24())
                            rawBitmapData1ByteComponent = bitmap24Rgb.ToRawBitmapData();
                    }
                }
            }

            var data = rawBitmapData1ByteComponent;

            var r  = new ByteImage(rawBitmapData1ByteComponent.PixelWidth, rawBitmapData1ByteComponent.PixelHeight);
            var yc = new Vector3(66, 129, 25);

            rawBitmapData1ByteComponent.PerPixelInArea(area, (dx, dy, A, R, G, B) =>
            {
                Vector3 sv;
                sv.Z = R;
                sv.Y = G;
                sv.X = B;

                r[dx, dy] = (byte)(((int)(Vector3.Dot(yc, sv) + 128) >> 8) + 16);
            });

            return(r);
        }