Пример #1
0
        public WebLayer(WebRenderer renderer, int width, int height, BaseLayout layout)
        {
            this.renderer     = renderer;
            this.width        = width;
            this.height       = height;
            Layout            = layout;
            CanvasInformation = CanvasInformation.Create(width, height);
            settingsStack     = new List <WebContextSettings>();

            settingsStack.Add(new WebContextSettings());
        }
        private CanvasInformation colorizeImage(HTMLImageElement img, Color color)
        {
            var canvas = CanvasInformation.Create(img.Width, img.Height);

            canvas.Context.DrawImage(img, 0, 0, img.NaturalWidth, img.NaturalHeight, 0, 0, img.Width, img.Height);
            var originalPixels = canvas.Context.GetImageData(0, 0, img.Width, img.Height);
            var currentPixels  = canvas.Context.GetImageData(0, 0, img.Width, img.Height);

            var L = originalPixels.Data.Length;

            for (var I = 0; I < L; I += 4)
            {
                currentPixels.Data[I]     = (byte)(originalPixels.Data[I] / 255d * color.R % 256);
                currentPixels.Data[I + 1] = (byte)(originalPixels.Data[I + 1] / 255d * color.G % 256);
                currentPixels.Data[I + 2] = (byte)(originalPixels.Data[I + 2] / 255d * color.B % 256);
                currentPixels.Data[I + 3] = (byte)(originalPixels.Data[I + 3] / 255d * color.A % 256);
            }

            canvas.Context.PutImageData(currentPixels, 0, 0);

            return(canvas);
        }
Пример #3
0
        public WebImage FlipVersion(DrawingEffects drawingEffects)
        {
            if (!flipVersions.ContainsKey(drawingEffects))
            {
                CanvasInformation canvas;
                switch (drawingEffects)
                {
                case DrawingEffects.None:

                    flipVersions.Add(DrawingEffects.None, this);
                    break;

                case DrawingEffects.FlipHorizontally:

                    canvas = CanvasInformation.Create(Width, Height);
                    canvas.Context.Translate(Width, 0);
                    canvas.Context.Scale(-1, 1);
                    canvas.Context.DrawImage(Image, 0, 0);

                    flipVersions.Add(DrawingEffects.FlipHorizontally, new WebImage(canvas.Canvas, Center));

                    break;

                case DrawingEffects.FlipVertically:
                    canvas = CanvasInformation.Create(Width, Height);
                    canvas.Context.Translate(0, Height);
                    canvas.Context.Scale(1, -1);
                    canvas.Context.DrawImage(Image, 0, 0);

                    flipVersions.Add(DrawingEffects.FlipVertically, new WebImage(canvas.Canvas, Center));
                    break;

                default:
                    throw new ArgumentOutOfRangeException("drawingEffects");
                }
            }

            return(flipVersions[drawingEffects]);
        }