示例#1
0
        ///////////////////////////////////////////////////////////////////////////

        private static int GetColor(Layer.Mask mask, int x, int y)
        {
            int c = 255;

            if (mask.PositionIsRelative)
            {
                x -= mask.Rect.X;
                y -= mask.Rect.Y;
            }
            else
            {
                x = (x + mask.Layer.Rect.X) - mask.Rect.X;
                y = (y + mask.Layer.Rect.Y) - mask.Rect.Y;
            }

            if (y >= 0 && y < mask.Rect.Height &&
                x >= 0 && x < mask.Rect.Width)
            {
                int pos = y * mask.Rect.Width + x;
                if (pos < mask.ImageData.Length)
                {
                    c = mask.ImageData[pos];
                }
                else
                {
                    c = 255;
                }
            }

            return(c);
        }
示例#2
0
        ///////////////////////////////////////////////////////////////////////////

        public static Bitmap DecodeImage(Layer.Mask mask)
        {
            Layer layer = mask.Layer;

            if (mask.Rect.Width == 0 || mask.Rect.Height == 0)
            {
                return(null);
            }

            Bitmap bitmap = new Bitmap(mask.Rect.Width, mask.Rect.Height, PixelFormat.Format32bppArgb);

            Rectangle  r  = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            BitmapData bd = bitmap.LockBits(r, ImageLockMode.ReadWrite, bitmap.PixelFormat);

            unsafe
            {
                byte *pCurrRowPixel = (byte *)bd.Scan0.ToPointer();

                for (int y = 0; y < mask.Rect.Height; y++)
                {
                    int        rowIndex   = y * mask.Rect.Width;
                    PixelData *pCurrPixel = (PixelData *)pCurrRowPixel;
                    for (int x = 0; x < mask.Rect.Width; x++)
                    {
                        int pos = rowIndex + x;

                        Color pixelColor = Color.FromArgb(mask.ImageData[pos], mask.ImageData[pos], mask.ImageData[pos]);

                        pCurrPixel->Alpha = 255;
                        pCurrPixel->Red   = pixelColor.R;
                        pCurrPixel->Green = pixelColor.G;
                        pCurrPixel->Blue  = pixelColor.B;

                        pCurrPixel += 1;
                    }
                    pCurrRowPixel += bd.Stride;
                }
            }

            bitmap.UnlockBits(bd);

            return(bitmap);
        }