Example #1
0
        public static System.Drawing.Bitmap GenMask(
            ITextStrategy strategy,
            int width,
            int height,
            System.Drawing.Point offset,
            TextContext textContext,
            Matrix mat)
        {
            if (strategy == null || textContext == null)
            {
                return(null);
            }

            System.Drawing.Bitmap pBmp = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppArgb);

            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(pBmp))
            {
                graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                graphics.Transform = mat;

                strategy.DrawString(graphics,
                                    textContext.fontFamily,
                                    textContext.fontStyle,
                                    textContext.nfontSize,
                                    textContext.pszText,
                                    new System.Drawing.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y),
                                    textContext.strFormat);

                graphics.ResetTransform();
            }

            return(pBmp);
        }
Example #2
0
        public static bool DrawTextImage(
            ITextStrategy strategy,
            System.Drawing.Bitmap image,
            System.Drawing.Point offset,
            TextContext textContext,
            Matrix mat)
        {
            if (strategy == null || image == null || textContext == null)
            {
                return(false);
            }

            bool bRet = false;

            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image))
            {
                graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                graphics.Transform = mat;

                bRet = strategy.DrawString(graphics,
                                           textContext.fontFamily,
                                           textContext.fontStyle,
                                           textContext.nfontSize,
                                           textContext.pszText,
                                           new System.Drawing.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y),
                                           textContext.strFormat);

                graphics.ResetTransform();
            }

            return(bRet);
        }
Example #3
0
        // Draw Faked Beveled effect
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            Bitmap canvas = Canvas.GenImage(ClientSize.Width, ClientSize.Height);

            // Text context to store string and font info to be sent as parameter to Canvas methods
            TextContext context = new TextContext();

            // Load a font from its file into private collection,
            // instead of from system font collection
            //=============================================================
            PrivateFontCollection fontcollection = new PrivateFontCollection();

            string szFontFile = "..\\..\\..\\CommonFonts\\Segoe Print.TTF";

            fontcollection.AddFontFile(szFontFile);
            if (fontcollection.Families.Count() > 0)
                context.fontFamily = fontcollection.Families[0];

            context.fontStyle = FontStyle.Regular;
            context.nfontSize = 38;

            context.pszText = "Love Like Magic";
            context.ptDraw = new Point(0, 0);

            // Draw the main outline
            //==========================================================
            ITextStrategy mainOutline = Canvas.TextOutline(Color.FromArgb(235, 10, 230), Color.FromArgb(235, 10, 230), 4);
            Canvas.DrawTextImage(mainOutline, canvas, new Point(4, 4), context);

            // Draw the small bright outline shifted (-2, -2)
            //==========================================================
            ITextStrategy mainBright = Canvas.TextOutline(Color.FromArgb(252, 173, 250), Color.FromArgb(252, 173, 250), 2);
            Canvas.DrawTextImage(mainBright, canvas, new Point(2, 2), context);

            // Draw the small dark outline shifted (+2, +2)
            //==========================================================
            ITextStrategy mainDark = Canvas.TextOutline(Color.FromArgb(126, 5, 123), Color.FromArgb(126, 5, 123), 2);
            Canvas.DrawTextImage(mainDark, canvas, new Point(6, 6), context);

            // Draw the smallest outline (color same as main outline)
            //==========================================================
            ITextStrategy mainInner = Canvas.TextOutline(Color.FromArgb(235, 10, 230), Color.FromArgb(235, 10, 230), 2);
            Canvas.DrawTextImage(mainInner, canvas, new Point(4, 4), context);

            // Finally blit the rendered canvas onto the window
            e.Graphics.DrawImage(canvas, 0, 0, ClientSize.Width, ClientSize.Height);

            // Release all the resources
            //============================
            canvas.Dispose();

            mainOutline.Dispose();
            mainBright.Dispose();
            mainDark.Dispose();
            mainInner.Dispose();
        }
Example #4
0
        public static System.Drawing.Bitmap GenMask(
            ITextStrategy strategy,
            int width,
            int height,
            System.Drawing.Point offset,
            TextContext textContext,
            Matrix mat)
        {
            if (strategy == null || textContext == null)
                return null;

            System.Drawing.Bitmap pBmp = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppArgb);

            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(pBmp))
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                graphics.Transform = mat;

                strategy.DrawString(graphics,
                    textContext.fontFamily,
                    textContext.fontStyle,
                    textContext.nfontSize,
                    textContext.pszText,
                    new System.Drawing.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y),
                    textContext.strFormat);

                graphics.ResetTransform();
            }

            return pBmp;
        }
Example #5
0
        public static bool DrawTextImage(
            ITextStrategy strategy,
            System.Drawing.Bitmap image,
            System.Drawing.Point offset,
            TextContext textContext,
            Matrix mat)
        {
            if (strategy == null || image == null || textContext == null)
                return false;

            bool bRet = false;
            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image))
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                graphics.Transform = mat;

                bRet = strategy.DrawString(graphics,
                    textContext.fontFamily,
                    textContext.fontStyle,
                    textContext.nfontSize,
                    textContext.pszText,
                    new System.Drawing.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y),
                    textContext.strFormat);

                graphics.ResetTransform();
            }

            return bRet;
        }
Example #6
0
        // Create the extruded text effect
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            // Create the outline strategy which is going to shift blit diagonally
            var strategyOutline = Canvas.TextOutline(MaskColor.Blue, MaskColor.Blue, 4);

            Bitmap canvas = Canvas.GenImage(ClientSize.Width, ClientSize.Height, Color.White, 0);

            // Text context to store string and font info to be sent as parameter to Canvas methods
            TextContext context = new TextContext();

            FontFamily fontFamily = new FontFamily("Arial Black");

            context.fontFamily = fontFamily;
            context.fontStyle = FontStyle.Regular;
            context.nfontSize = 40;

            context.pszText = "CODING MONKEY";
            context.ptDraw = new Point(0, 0);

            // the single mask outline
            Bitmap maskOutline = Canvas.GenMask(strategyOutline, ClientSize.Width, ClientSize.Height, new Point(0, 0), context);
            // the mask to store all the single mask blitted diagonally
            Bitmap maskOutlineAll = Canvas.GenImage(ClientSize.Width + 10, ClientSize.Height + 10);

            Graphics graphMaskAll = Graphics.FromImage(maskOutlineAll);

            // blit diagonally
            for (int i = 0; i < 7; ++i)
                graphMaskAll.DrawImage(maskOutline, i, i, ClientSize.Width, ClientSize.Height);

            // Measure the dimension of the big mask in order to generate the correct sized gradient image
            //=============================================================================================
            uint top = 0;
            uint bottom = 0;
            uint left = 0;
            uint right = 0;
            Canvas.MeasureMaskLength(maskOutlineAll, MaskColor.Blue, ref top, ref left, ref bottom, ref right);
            right += 2;
            bottom += 2;

            // Generate the gradient image for the diagonal outline
            //=======================================================
            Bitmap gradImage = Canvas.GenImage((int)(right - left), (int)(bottom - top));

            List<Color> listColors = new List<Color>();
            listColors.Add(Color.DarkGreen);
            listColors.Add(Color.YellowGreen);
            DrawGradient.Draw(gradImage, listColors, false);

            // Because Canvas::ApplyImageToMask requires all image to have same dimensions,
            // we have to blit our small gradient image onto a temp image as big as the canvas
            //===================================================================================
            Bitmap gradBlitted = Canvas.GenImage(ClientSize.Width, ClientSize.Height);

            Graphics graphgradBlitted = Graphics.FromImage(gradBlitted);

            graphgradBlitted.DrawImage(gradImage, (int)left, (int)top, (int)(gradImage.Width), (int)(gradImage.Height));

            Canvas.ApplyImageToMask(gradBlitted, maskOutlineAll, canvas, MaskColor.Blue, false);

            // Create strategy and mask image for the text body
            //===================================================
            var strategyText = Canvas.TextNoOutline(MaskColor.Blue);
            Bitmap maskText = Canvas.GenMask(strategyText, ClientSize.Width, ClientSize.Height, new Point(0, 0), context);

            // Measure the dimension required for text body using the mask
            //=============================================================
            top = 0;
            bottom = 0;
            left = 0;
            right = 0;
            Canvas.MeasureMaskLength(maskText, MaskColor.Blue, ref top, ref left, ref bottom, ref right);
            top -= 2;
            left -= 2;

            right += 2;
            bottom += 2;

            // Create the gradient brush for the text body
            LinearGradientBrush gradTextbrush = new LinearGradientBrush(new Rectangle((int)left, (int)top, (int)right, (int)bottom), Color.Orange, Color.OrangeRed, 90.0f);
            // Create the actual strategy for the text body used for rendering, with the gradient brush
            var strategyText2 = Canvas.TextNoOutline(gradTextbrush);
            // Draw the newly created strategy onto the canvas
            Canvas.DrawTextImage(strategyText2, canvas, new Point(0, 0), context);

            // Finally blit the rendered canvas onto the window
            e.Graphics.DrawImage(canvas, 0, 0, ClientSize.Width, ClientSize.Height);

            // Release all the resources
            //============================
            maskOutline.Dispose();
            maskOutlineAll.Dispose();

            gradImage.Dispose();
            gradBlitted.Dispose();
            maskText.Dispose();

            canvas.Dispose();

            strategyText.Dispose();
            strategyText2.Dispose();
            strategyOutline.Dispose();

            gradTextbrush.Dispose();
        }
Example #7
0
        void DrawChar( int x_offset, Rectangle rect, TextContext context, Graphics graphics, Matrix mat )
        {
            Bitmap canvas = Canvas.GenImage(ClientSize.Width, ClientSize.Height, Color.White, 0);

            // Create the outline strategy which is going to shift blit diagonally
            var strategyOutline = Canvas.TextOutline(MaskColor.Blue, MaskColor.Blue, 4);

            // the single mask outline
            Bitmap maskOutline = Canvas.GenMask(strategyOutline, rect.Width, rect.Height, new Point(0,0), context, mat);
            // the mask to store all the single mask blitted diagonally
            Bitmap maskOutlineAll = Canvas.GenImage(rect.Width+10, rect.Height+10);

            Graphics graphMaskAll = Graphics.FromImage(maskOutlineAll);

            // blit diagonally
            for(int i=0; i<8; ++i)
                graphMaskAll.DrawImage(maskOutline, -i, -i, rect.Width, rect.Height);

            // Measure the dimension of the big mask in order to generate the correct sized gradient image
            //=============================================================================================
            UInt32 top = 0;
            UInt32 bottom = 0;
            UInt32 left = 0;
            UInt32 right = 0;
            Canvas.MeasureMaskLength(maskOutlineAll, MaskColor.Blue, ref top, ref left, ref bottom, ref right);
            right += 2;
            bottom += 2;

            // Generate the gradient image for the diagonal outline
            //=======================================================
            Bitmap gradImage = Canvas.GenImage((int)(right-left), (int)(bottom-top));

            List<Color> listColors = new List<Color>();
            listColors.Add(Color.Purple);
            listColors.Add(Color.MediumPurple);
            DrawGradient.Draw(gradImage, listColors, false);

            // Because Canvas::ApplyImageToMask requires all image to have same dimensions,
            // we have to blit our small gradient image onto a temp image as big as the canvas
            //===================================================================================
            Bitmap gradBlitted = Canvas.GenImage(rect.Width, rect.Height);

            Graphics graphgradBlitted = Graphics.FromImage(gradBlitted);

            graphgradBlitted.DrawImage(gradImage, (int)left, (int)top, (int)(gradImage.Width), (int)(gradImage.Height));

            Canvas.ApplyImageToMask(gradBlitted, maskOutlineAll, canvas, MaskColor.Blue, false);

            // Create strategy and mask image for the text body
            //===================================================
            var strategyText = Canvas.TextNoOutline(MaskColor.Blue);
            Bitmap maskText = Canvas.GenMask(strategyText, rect.Width, rect.Height, new Point(0,0), context, mat);

            // Measure the dimension required for text body using the mask
            //=============================================================
            top = 0;
            bottom = 0;
            left = 0;
            right = 0;
            Canvas.MeasureMaskLength(maskText, MaskColor.Blue, ref top, ref left, ref bottom, ref right);
            top -= 2;
            left -= 2;

            right += 2;
            bottom += 2;

            // Create the gradient brush for the text body
            LinearGradientBrush gradTextbrush = new LinearGradientBrush(new Rectangle((int)left, (int)top, (int)right, (int)bottom), Color.DeepPink, Color.LightPink, 90.0f);

            // Create the actual strategy for the text body used for rendering, with the gradient brush
            var strategyText2 = Canvas.TextNoOutline(gradTextbrush);

            // Draw the newly created strategy onto the canvas
            Canvas.DrawTextImage(strategyText2, canvas, new Point(0,0), context, mat);

            // Finally blit the rendered canvas onto the window
            graphics.DrawImage(canvas, x_offset, 0, rect.Width, rect.Height);

            gradImage.Dispose();
            gradBlitted.Dispose();

            maskText.Dispose();

            strategyText.Dispose();
            strategyText2.Dispose();

            maskOutline.Dispose();
            maskOutlineAll.Dispose();

            strategyOutline.Dispose();

            canvas.Dispose();
        }
Example #8
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            // Text context to store string and font info to be sent as parameter to Canvas methods
            TextContext context = new TextContext();

            context.fontStyle = FontStyle.Regular;
            context.nfontSize = 40;

            context.ptDraw = new Point(0, 5);

            string szFontFile = "..\\..\\..\\CommonFonts\\Airbus Special.TTF";

            PrivateFontCollection fontcollection = new PrivateFontCollection();

            fontcollection.AddFontFile(szFontFile);
            if (fontcollection.Families.Count() > 0)
                context.fontFamily = fontcollection.Families[0];

            string text = "PENTHOUSE";
            int x_offset = 0;

            for(int i=0; i<text.Length; ++i)
            {
                string str = "";
                str += text[i];
                context.pszText = str;

                Matrix mat = new Matrix();
                mat.Rotate(-10.0f, MatrixOrder.Append);
                mat.Scale(0.75f, 1.0f, MatrixOrder.Append);
                DrawChar(x_offset, new Rectangle(0, 0, ClientSize.Width, ClientSize.Height), context, e.Graphics, mat);

                if(i==2)
                    x_offset += 42;
                else if(i>=4&&i<=6)
                    x_offset += 42;
                else if(i==7)
                    x_offset += 37;
                else
                    x_offset += 39;

                x_offset -= 8;
            }
        }
Example #9
0
        // Create dirty text effect
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            Bitmap canvas = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            // Load the dirty image from file
            Bitmap canvasDirty = new Bitmap("..\\..\\..\\CommonImages\\dirty-texture.png");

            // Text context to store string and font info to be sent as parameter to Canvas methods
            TextContext context = new TextContext();

            FontFamily fontFamily = new FontFamily("Arial Black");
            context.fontFamily = fontFamily;
            context.fontStyle = FontStyle.Regular;
            context.nfontSize = 48;

            context.pszText = "DIRTY";
            context.ptDraw = new Point(5, 70);

            // Load the texture image from file
            Bitmap texture = new Bitmap("..\\..\\..\\CommonImages\\texture_blue.jpg");

            Bitmap texture2 = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            // Draw the texture against the red dirty mask onto the 2nd texture
            Canvas.ApplyImageToMask(texture, canvasDirty, texture2, MaskColor.Red, false);
            TextureBrush textureBrush = new TextureBrush(texture2);

            Bitmap textureShadow = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            // Draw the gray color against the red dirty mask onto the shadow texture
            Canvas.ApplyColorToMask(Color.FromArgb(0xaa, 0xcc, 0xcc, 0xcc), canvasDirty, textureShadow, MaskColor.Red);
            // Create texture brush for the shadow
            TextureBrush shadowBrush = new TextureBrush(textureShadow);

            // Create strategy for the shadow with the shadow brush
            var strategyShadow = Canvas.TextNoOutline(shadowBrush);

            Bitmap canvasTemp = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            // Draw the shadow image first onto the temp canvas
            Canvas.DrawTextImage(strategyShadow, canvasTemp, new Point(0, 0), context);

            // Create strategy for the text body
            var strategy = Canvas.TextNoOutline(textureBrush);
            // Draw text body
            Canvas.DrawTextImage(strategy, canvas, new Point(0,0), context);

            // Draw the shadow image (canvasTemp) shifted -3, -3
            e.Graphics.DrawImage(canvasTemp, 3, 3, ClientSize.Width - 3, ClientSize.Height - 3);
            // Then draw the rendered image onto window
            e.Graphics.DrawImage(canvas, 0, 0, ClientSize.Width, ClientSize.Height);

            e.Graphics.Dispose();
            texture.Dispose();
            texture2.Dispose();
            textureShadow.Dispose();

            canvasDirty.Dispose();

            canvas.Dispose();
            canvasTemp.Dispose();

            strategyShadow.Dispose();
            strategy.Dispose();

            textureBrush.Dispose();
            shadowBrush.Dispose();
        }
Example #10
0
        // Generating the hollow text effect where the text looks like cut out of canvas
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            // Generating the outline strategy for displaying inside the hollow
            var strategyOutline = Canvas.TextGradOutline(Color.FromArgb(255, 255, 255), Color.FromArgb(230, 230, 230), Color.FromArgb(100, 100, 100), 9);

            Bitmap canvas = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            // Text context to store string and font info to be sent as parameter to Canvas methods
            TextContext context = new TextContext();

            FontFamily fontFamily = new FontFamily("Arial Black");

            context.fontFamily = fontFamily;
            context.fontStyle = FontStyle.Bold;
            context.nfontSize = 56;

            context.pszText = "CUTOUT";
            context.ptDraw = new Point(0, 0);

            Bitmap hollowImage = Canvas.GenImage(ClientSize.Width, ClientSize.Height);

            // Algorithm to shift the shadow outline in and then out continuous
            int shift = 0;
            if (_TimerLoop >= 0 && _TimerLoop <= 2)
                shift = _TimerLoop;
            else
                shift = 2 - (_TimerLoop - 2);

            // Draw the hollow (shadow) outline by shifting accordingly
            Canvas.DrawTextImage(strategyOutline, hollowImage, new Point(2 + shift, 2 + shift), context);

            // Generate the green mask for the cutout holes in the text
            Bitmap maskImage = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            var strategyMask = Canvas.TextOutline(MaskColor.Green, MaskColor.Green, 0);
            Canvas.DrawTextImage(strategyMask, maskImage, new Point(0, 0), context);

            // Apply the hollowed image against the green mask on the canvas
            Canvas.ApplyImageToMask(hollowImage, maskImage, canvas, MaskColor.Green, false);

            Bitmap backBuffer = Canvas.GenImage(ClientSize.Width, ClientSize.Height, Color.FromArgb(0, 0, 0), 255);

            // Create a black outline only strategy and blit it onto the canvas to cover
            // the unnatural outline from the gradient shadow
            //=============================================================================
            var strategyOutlineOnly = Canvas.TextOnlyOutline(Color.FromArgb(0, 0, 0), 2, false);
            Canvas.DrawTextImage(strategyOutlineOnly, canvas, new Point(0, 0), context);

            // Draw the transparent canvas onto the back buffer
            //===================================================
            Graphics graphics2 = Graphics.FromImage(backBuffer);
            graphics2.SmoothingMode = SmoothingMode.AntiAlias;
            graphics2.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics2.DrawImage(canvas, 0, 0, ClientSize.Width, ClientSize.Height);

            // Finally blit the rendered image onto the window
            e.Graphics.DrawImage(backBuffer, 0, 0, ClientSize.Width, ClientSize.Height);

            // Release all the resources
            //============================
            hollowImage.Dispose();
            maskImage.Dispose();
            canvas.Dispose();
            backBuffer.Dispose();

            strategyOutline.Dispose();
            strategyMask.Dispose();
            strategyOutlineOnly.Dispose();
        }
Example #11
0
        // Create rainbow Text Effect in Aquarion EVOL anime
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            // Create the outline strategy which is used later on for measuring
            // the size of text in order to generate a correct sized gradient image
            var strategyOutline2 = Canvas.TextOutline(MaskColor.Blue, MaskColor.Blue, 8);

            Bitmap canvas = Canvas.GenImage(ClientSize.Width, ClientSize.Height, Color.White, 0);

            // Text context to store string and font info to be sent as parameter to Canvas methods
            TextContext context = new TextContext();

            // Load a font from its file into private collection,
            // instead of from system font collection
            //=============================================================
            PrivateFontCollection fontcollection = new PrivateFontCollection();

            string szFontFile = "..\\..\\..\\CommonFonts\\Ruzicka TypeK.ttf";

            fontcollection.AddFontFile(szFontFile);

            if(fontcollection.Families.Count()>0)
                context.fontFamily = fontcollection.Families[0];
            context.fontStyle = FontStyle.Regular;
            context.nfontSize = 36;

            context.pszText = "I cross over the deep blue void";
            context.ptDraw = new Point(0, 0);

            // Generate the mask image for measuring the size of the text image required
            //============================================================================
            Bitmap maskOutline2 = Canvas.GenMask(strategyOutline2, ClientSize.Width, ClientSize.Height, new Point(0, 0), context);

            uint top = 0;
            uint bottom = 0;
            uint left = 0;
            uint right = 0;
            Canvas.MeasureMaskLength(maskOutline2, MaskColor.Blue, ref top, ref left, ref bottom, ref right);
            bottom += 2;
            right += 2;

            // Generate the gradient image
            //=============================
            Bitmap bmpGrad = new Bitmap((int)(right - left), (int)(bottom - top), PixelFormat.Format32bppArgb);
            List<Color> list = new List<Color>();
            list.Add(Color.FromArgb(255, 0, 0));
            list.Add(Color.FromArgb(0, 0, 255));
            list.Add(Color.FromArgb(0, 255, 0));
            DrawGradient.Draw(bmpGrad, list, true);

            // Because Canvas::ApplyImageToMask requires the all images to have equal dimension,
            // we need to blit our new gradient image onto a larger image to be same size as canvas image
            //==============================================================================================
            Bitmap bmpGrad2 = new Bitmap(ClientSize.Width, ClientSize.Height, PixelFormat.Format32bppArgb);
            Graphics graphGrad = Graphics.FromImage(bmpGrad2);
            graphGrad.SmoothingMode = SmoothingMode.AntiAlias;
            graphGrad.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphGrad.DrawImage(bmpGrad, (int)left, (int)top, (int)(right - left), (int)(bottom - top));

            // Apply the rainbow text against the blue mask onto the canvas
            Canvas.ApplyImageToMask(bmpGrad2, maskOutline2, canvas, MaskColor.Blue, false);

            // Draw the (white body and black outline) text onto the canvas
            //==============================================================
            var strategyOutline1 = Canvas.TextOutline(Color.FromArgb(255, 255, 255), Color.FromArgb(0, 0, 0), 4);
            Canvas.DrawTextImage(strategyOutline1, canvas, new Point(0, 0), context);

            // Finally blit the rendered image onto the window
            e.Graphics.DrawImage(canvas, 0, 0, ClientSize.Width, ClientSize.Height);

            // Release all the resources
            //============================
            e.Graphics.Dispose();

            bmpGrad.Dispose();
            bmpGrad2.Dispose();
            canvas.Dispose();

            maskOutline2.Dispose();
            strategyOutline2.Dispose();
            strategyOutline1.Dispose();
        }
Example #12
0
        // Draw the BE HAPPY effect from the BE HAPPY soap opera
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            // Create canvas to be rendered
            Bitmap canvas = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            // Create canvas for the green outermost outline
            Bitmap canvasOuter = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
            // Create canvas for the white inner outline
            Bitmap canvasInner = Canvas.GenImage(ClientSize.Width, ClientSize.Height);

            // Text context to store string and font info to be sent as parameter to Canvas methods
            TextContext context = new TextContext();

            // Load a font from its file into private collection,
            // instead of from system font collection
            //=============================================================
            PrivateFontCollection fontcollection = new PrivateFontCollection();

            string szFontFile = "..\\..\\..\\CommonFonts\\ALBA____.TTF";

            fontcollection.AddFontFile(szFontFile);
            if (fontcollection.Families.Count() > 0)
                context.fontFamily = fontcollection.Families[0];
            context.fontStyle = FontStyle.Regular;
            context.nfontSize = 48;

            context.pszText = "bE";
            context.ptDraw = new Point(55, 0);

            // Create the outer strategy to draw the bE text
            var strategyOutline2 = Canvas.TextOutline(Color.LightSeaGreen, Color.LightSeaGreen, 16);
            // Draw the bE text (outer green outline)
            Canvas.DrawTextImage(strategyOutline2, canvasOuter, new Point(0, 0), context);
            context.pszText = "Happy";
            context.ptDraw = new Point(0, 48);
            // Draw the Happy text (outer green outline)
            Canvas.DrawTextImage(strategyOutline2, canvasOuter, new Point(0, 0), context);

            // blit the canvasOuter all the way down (5 pixels down)
            //========================================================
            Graphics graphicsCanvas = Graphics.FromImage(canvas);
            graphicsCanvas.SmoothingMode = SmoothingMode.AntiAlias;
            graphicsCanvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphicsCanvas.DrawImage(canvasOuter, 0, 0, ClientSize.Width, ClientSize.Height);
            graphicsCanvas.DrawImage(canvasOuter, 0, 1, ClientSize.Width, ClientSize.Height);
            graphicsCanvas.DrawImage(canvasOuter, 0, 2, ClientSize.Width, ClientSize.Height);
            graphicsCanvas.DrawImage(canvasOuter, 0, 3, ClientSize.Width, ClientSize.Height);
            graphicsCanvas.DrawImage(canvasOuter, 0, 4, ClientSize.Width, ClientSize.Height);
            graphicsCanvas.DrawImage(canvasOuter, 0, 5, ClientSize.Width, ClientSize.Height);
            e.Graphics.DrawImage(canvas, 0, 0, ClientSize.Width, ClientSize.Height);

            context.pszText = "bE";
            context.ptDraw = new Point(55, 0);

            // Create the inner white strategy
            var strategyOutline1 = Canvas.TextOutline(Color.White, Color.White, 8);
            // Draw the bE text (inner white outline)
            Canvas.DrawTextImage(strategyOutline1, canvasInner, new Point(0, 0), context);

            context.pszText = "Happy";
            context.ptDraw = new Point(0, 48);
            // Draw the Happy text (inner white outline)
            Canvas.DrawTextImage(strategyOutline1, canvasInner, new Point(0, 0), context);

            // blit the canvasInner all the way down (5 pixels down)
            //========================================================
            graphicsCanvas.DrawImage(canvasInner, 0, 0, ClientSize.Width, ClientSize.Height);
            graphicsCanvas.DrawImage(canvasInner, 0, 1, ClientSize.Width, ClientSize.Height);
            graphicsCanvas.DrawImage(canvasInner, 0, 2, ClientSize.Width, ClientSize.Height);
            graphicsCanvas.DrawImage(canvasInner, 0, 3, ClientSize.Width, ClientSize.Height);
            graphicsCanvas.DrawImage(canvasInner, 0, 4, ClientSize.Width, ClientSize.Height);
            graphicsCanvas.DrawImage(canvasInner, 0, 5, ClientSize.Width, ClientSize.Height);
            e.Graphics.DrawImage(canvas, 0, 0, ClientSize.Width, ClientSize.Height);

            // Create the strategy for green text body
            var strategyOutline = Canvas.TextOutline(Color.LightSeaGreen, Color.LightSeaGreen, 1);

            context.pszText = "bE";
            context.ptDraw = new Point(55, 0);
            // Draw the bE text (text body)
            Canvas.DrawTextImage(strategyOutline, canvas, new Point(0, 0), context);

            context.pszText = "Happy";
            context.ptDraw = new Point(0, 48);
            // Draw the Happy text (text body)
            Canvas.DrawTextImage(strategyOutline, canvas, new Point(0, 0), context);

            // Finally blit the rendered canvas onto the window
            e.Graphics.DrawImage(canvas, 0, 0, ClientSize.Width, ClientSize.Height);

            // Release all the resources
            //============================
            e.Graphics.Dispose();

            canvasOuter.Dispose();

            canvasInner.Dispose();

            canvas.Dispose();

            strategyOutline2.Dispose();
            strategyOutline1.Dispose();
            strategyOutline.Dispose();
        }