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); } }
// 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(); }
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(); }