public async Task <Size> DrawVacationText(int dim, string font, string text, string saved_file) { Size size = new Size(); CanvasDevice device = CanvasDevice.GetSharedDevice(); using (CanvasRenderTarget offscreen = CanvasHelper.GenImage(dim, dim, Colors.White)) { CanvasTextFormat format = new CanvasTextFormat(); format.FontFamily = font; format.FontStyle = Windows.UI.Text.FontStyle.Normal; format.FontSize = 52; format.FontWeight = Windows.UI.Text.FontWeights.Black; float layoutWidth = dim; float layoutHeight = dim; CanvasTextLayout textLayout = new CanvasTextLayout(device, text, format, layoutWidth, layoutHeight); Color light_purple = Color.FromArgb(255, 102, 159, 206); Color dark_purple = Color.FromArgb(255, 35, 68, 95); Point pt = new Point(10.0, 10.0); using (var strategyOutline3 = CanvasHelper.TextGradOutline(light_purple, dark_purple, light_purple, 9, GradientType.Linear)) { CanvasHelper.DrawTextImage(strategyOutline3, offscreen, pt, textLayout); } CanvasRenderTarget maskOutline2; using (var strategyOutline2 = CanvasHelper.TextNoOutline(MaskColor.Blue)) { maskOutline2 = CanvasHelper.GenMask(strategyOutline2, dim, dim, pt, textLayout); } Color light_yellow = Color.FromArgb(255, 255, 227, 85); Color dark_yellow = Color.FromArgb(255, 243, 163, 73); using (CanvasRenderTarget text_image = CanvasHelper.GenImage(dim, dim, dark_yellow)) { using (var strategyText2 = CanvasHelper.TextGradOutlineLast(light_yellow, dark_yellow, light_yellow, 9, GradientType.Sinusoid)) { CanvasHelper.DrawTextImage(strategyText2, text_image, pt, textLayout); CanvasHelper.ApplyImageToMask(text_image, maskOutline2, offscreen, MaskColor.Blue, true); } } Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder; string saved_file2 = "\\"; saved_file2 += saved_file; await offscreen.SaveAsync(storageFolder.Path + saved_file2); imgOutlineText.Source = new BitmapImage(new Uri(storageFolder.Path + saved_file2)); return(size); } }
public async Task <Size> DrawOutlineTextWithLibrary(int dim, string font, string text, string saved_file) { Size size = new Size(); CanvasDevice device = CanvasDevice.GetSharedDevice(); using (CanvasRenderTarget offscreen = new CanvasRenderTarget(device, dim, dim, 96, Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized, CanvasAlphaMode.Premultiplied)) { using (CanvasDrawingSession ds = offscreen.CreateDrawingSession()) { ds.Clear(Colors.White); } Color text_color = Colors.White; CanvasSolidColorBrush brush = new CanvasSolidColorBrush(device, text_color); CanvasTextFormat format = new CanvasTextFormat(); format.FontFamily = font; format.FontStyle = Windows.UI.Text.FontStyle.Normal; format.FontSize = 60; format.FontWeight = Windows.UI.Text.FontWeights.Bold; float layoutWidth = dim; float layoutHeight = dim; CanvasTextLayout textLayout = new CanvasTextLayout(device, text, format, layoutWidth, layoutHeight); ITextStrategy strat = CanvasHelper.TextOutline(Colors.Blue, Colors.Black, 10); CanvasHelper.DrawTextImage(strat, offscreen, new Point(10.0, 10.0), textLayout); Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder; string saved_file2 = "\\"; saved_file2 += saved_file; await offscreen.SaveAsync(storageFolder.Path + saved_file2); imgOutlineText.Source = new BitmapImage(new Uri(storageFolder.Path + saved_file2)); using (CanvasDrawingSession ds = offscreen.CreateDrawingSession()) { ds.Clear(Colors.White); } return(size); } }
// 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 = CanvasHelper.TextGradOutline(Color.FromArgb(255, 255, 255), Color.FromArgb(230, 230, 230), Color.FromArgb(100, 100, 100), 9, GradientType.Linear); Bitmap canvas = CanvasHelper.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 = CanvasHelper.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 CanvasHelper.DrawTextImage(strategyOutline, hollowImage, new Point(2 + shift, 2 + shift), context); // Generate the green mask for the cutout holes in the text Bitmap maskImage = CanvasHelper.GenImage(ClientSize.Width, ClientSize.Height); var strategyMask = CanvasHelper.TextOutline(MaskColor.Green, MaskColor.Green, 0); CanvasHelper.DrawTextImage(strategyMask, maskImage, new Point(0, 0), context); // Apply the hollowed image against the green mask on the canvas CanvasHelper.ApplyImageToMask(hollowImage, maskImage, canvas, MaskColor.Green, false); Bitmap backBuffer = CanvasHelper.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 = CanvasHelper.TextOnlyOutline(Color.FromArgb(0, 0, 0), 2, false); CanvasHelper.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(); }
// 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 = CanvasHelper.TextOutline(MaskColor.Blue, MaskColor.Blue, 4); Bitmap canvas = CanvasHelper.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 = CanvasHelper.GenMask(strategyOutline, ClientSize.Width, ClientSize.Height, new Point(0, 0), context); // the mask to store all the single mask blitted diagonally Bitmap maskOutlineAll = CanvasHelper.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; CanvasHelper.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 = CanvasHelper.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 = CanvasHelper.GenImage(ClientSize.Width, ClientSize.Height); Graphics graphgradBlitted = Graphics.FromImage(gradBlitted); graphgradBlitted.DrawImage(gradImage, (int)left, (int)top, (int)(gradImage.Width), (int)(gradImage.Height)); CanvasHelper.ApplyImageToMask(gradBlitted, maskOutlineAll, canvas, MaskColor.Blue, false); // Create strategy and mask image for the text body //=================================================== var strategyText = CanvasHelper.TextNoOutline(MaskColor.Blue); Bitmap maskText = CanvasHelper.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; CanvasHelper.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 = CanvasHelper.TextNoOutline(gradTextbrush); // Draw the newly created strategy onto the canvas CanvasHelper.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(); }
private void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; Bitmap canvas = CanvasHelper.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 = 54; context.pszText = "VACATION"; context.ptDraw = new Point(0, 0); Color light_purple = Color.FromArgb(102, 159, 206); Color dark_purple = Color.FromArgb(35, 68, 95); using (var strategyOutline3 = CanvasHelper.TextGradOutline(light_purple, dark_purple, light_purple, 9, GradientType.Linear)) { CanvasHelper.DrawTextImage(strategyOutline3, canvas, new Point(0, 0), context); } Bitmap maskOutline2; using (var strategyOutline2 = CanvasHelper.TextNoOutline(MaskColor.Blue)) { maskOutline2 = CanvasHelper.GenMask(strategyOutline2, ClientSize.Width, ClientSize.Height, new Point(0, 0), context); } uint top = 0; uint bottom = 0; uint left = 0; uint right = 0; CanvasHelper.MeasureMaskLength(maskOutline2, MaskColor.Blue, ref top, ref left, ref bottom, ref right); bottom += 2; right += 2; Color light_yellow = Color.FromArgb(255, 227, 85); Color dark_yellow = Color.FromArgb(243, 163, 73); using (Bitmap text = CanvasHelper.GenImage(ClientSize.Width, ClientSize.Height, dark_yellow)) { using (var strategyText2 = CanvasHelper.TextGradOutlineLast(light_yellow, dark_yellow, light_yellow, 9, GradientType.Sinusoid)) { CanvasHelper.DrawTextImage(strategyText2, text, new Point(0, 0), context); CanvasHelper.ApplyImageToMask(text, maskOutline2, canvas, MaskColor.Blue, true); } } // 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(); canvas.Dispose(); maskOutline2.Dispose(); }
// 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 = CanvasHelper.GenImage(ClientSize.Width, ClientSize.Height); // Create canvas for the green outermost outline Bitmap canvasOuter = CanvasHelper.GenImage(ClientSize.Width, ClientSize.Height); // Create canvas for the white inner outline Bitmap canvasInner = CanvasHelper.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 = CanvasHelper.TextOutline(Color.LightSeaGreen, Color.LightSeaGreen, 16); // Draw the bE text (outer green outline) CanvasHelper.DrawTextImage(strategyOutline2, canvasOuter, new Point(0, 0), context); context.pszText = "Happy"; context.ptDraw = new Point(0, 48); // Draw the Happy text (outer green outline) CanvasHelper.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 = CanvasHelper.TextOutline(Color.White, Color.White, 8); // Draw the bE text (inner white outline) CanvasHelper.DrawTextImage(strategyOutline1, canvasInner, new Point(0, 0), context); context.pszText = "Happy"; context.ptDraw = new Point(0, 48); // Draw the Happy text (inner white outline) CanvasHelper.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 = CanvasHelper.TextOutline(Color.LightSeaGreen, Color.LightSeaGreen, 1); context.pszText = "bE"; context.ptDraw = new Point(55, 0); // Draw the bE text (text body) CanvasHelper.DrawTextImage(strategyOutline, canvas, new Point(0, 0), context); context.pszText = "Happy"; context.ptDraw = new Point(0, 48); // Draw the Happy text (text body) CanvasHelper.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(); }
void DrawChar(int x_offset, Rectangle rect, TextContext context, Graphics graphics, Matrix mat) { Bitmap canvas = CanvasHelper.GenImage(ClientSize.Width, ClientSize.Height, Color.White, 0); // Create the outline strategy which is going to shift blit diagonally var strategyOutline = CanvasHelper.TextOutline(MaskColor.Blue, MaskColor.Blue, 4); // the single mask outline Bitmap maskOutline = CanvasHelper.GenMask(strategyOutline, rect.Width, rect.Height, new Point(0, 0), context, mat); // the mask to store all the single mask blitted diagonally Bitmap maskOutlineAll = CanvasHelper.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; CanvasHelper.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 = CanvasHelper.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 = CanvasHelper.GenImage(rect.Width, rect.Height); Graphics graphgradBlitted = Graphics.FromImage(gradBlitted); graphgradBlitted.DrawImage(gradImage, (int)left, (int)top, (int)(gradImage.Width), (int)(gradImage.Height)); CanvasHelper.ApplyImageToMask(gradBlitted, maskOutlineAll, canvas, MaskColor.Blue, false); // Create strategy and mask image for the text body //=================================================== var strategyText = CanvasHelper.TextNoOutline(MaskColor.Blue); Bitmap maskText = CanvasHelper.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; CanvasHelper.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 = CanvasHelper.TextNoOutline(gradTextbrush); // Draw the newly created strategy onto the canvas CanvasHelper.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(); }
// 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 = CanvasHelper.TextOutline(MaskColor.Blue, MaskColor.Blue, 8); Bitmap canvas = CanvasHelper.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 = CanvasHelper.GenMask(strategyOutline2, ClientSize.Width, ClientSize.Height, new Point(0, 0), context); uint top = 0; uint bottom = 0; uint left = 0; uint right = 0; CanvasHelper.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 CanvasHelper.ApplyImageToMask(bmpGrad2, maskOutline2, canvas, MaskColor.Blue, false); // Draw the (white body and black outline) text onto the canvas //============================================================== var strategyOutline1 = CanvasHelper.TextOutline(Color.FromArgb(255, 255, 255), Color.FromArgb(0, 0, 0), 4); CanvasHelper.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(); }
// Create dirty text effect private void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; Bitmap canvas = CanvasHelper.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 = CanvasHelper.GenImage(ClientSize.Width, ClientSize.Height); // Draw the texture against the red dirty mask onto the 2nd texture CanvasHelper.ApplyImageToMask(texture, canvasDirty, texture2, MaskColor.Red, false); TextureBrush textureBrush = new TextureBrush(texture2); Bitmap textureShadow = CanvasHelper.GenImage(ClientSize.Width, ClientSize.Height); // Draw the gray color against the red dirty mask onto the shadow texture CanvasHelper.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 = CanvasHelper.TextNoOutline(shadowBrush); Bitmap canvasTemp = CanvasHelper.GenImage(ClientSize.Width, ClientSize.Height); // Draw the shadow image first onto the temp canvas CanvasHelper.DrawTextImage(strategyShadow, canvasTemp, new Point(0, 0), context); // Create strategy for the text body var strategy = CanvasHelper.TextNoOutline(textureBrush); // Draw text body CanvasHelper.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(); }
// Draw Faked Beveled effect private void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; Bitmap canvas = CanvasHelper.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 = CanvasHelper.TextOutline(Color.FromArgb(235, 10, 230), Color.FromArgb(235, 10, 230), 4); CanvasHelper.DrawTextImage(mainOutline, canvas, new Point(4, 4), context); // Draw the small bright outline shifted (-2, -2) //========================================================== ITextStrategy mainBright = CanvasHelper.TextOutline(Color.FromArgb(252, 173, 250), Color.FromArgb(252, 173, 250), 2); CanvasHelper.DrawTextImage(mainBright, canvas, new Point(2, 2), context); // Draw the small dark outline shifted (+2, +2) //========================================================== ITextStrategy mainDark = CanvasHelper.TextOutline(Color.FromArgb(126, 5, 123), Color.FromArgb(126, 5, 123), 2); CanvasHelper.DrawTextImage(mainDark, canvas, new Point(6, 6), context); // Draw the smallest outline (color same as main outline) //========================================================== ITextStrategy mainInner = CanvasHelper.TextOutline(Color.FromArgb(235, 10, 230), Color.FromArgb(235, 10, 230), 2); CanvasHelper.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(); }