/// <summary> /// Generate mask image of the text strategy. /// </summary> /// <param name="strategy">is text strategy</param> /// <param name="width">is the mask image width</param> /// <param name="height">is the mask image height</param> /// <param name="offset">offsets the text (typically used for shadows)</param> /// <param name="textContext">is text context</param> /// <returns>a valid mask image if successful</returns> public static System.Windows.Media.Imaging.WriteableBitmap GenMask( ITextStrategy strategy, int width, int height, System.Windows.Point offset, TextContext textContext) { if (strategy == null || textContext == null) { return(null); } RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32); DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); strategy.DrawString(drawingContext, textContext.fontFamily, textContext.fontStyle, textContext.fontWeight, textContext.nfontSize, textContext.pszText, new System.Windows.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y), textContext.ci); drawingContext.Close(); bmp.Render(drawingVisual); return(new System.Windows.Media.Imaging.WriteableBitmap(bmp)); }
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); }
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); }
/// <summary> /// Draw outline on image /// </summary> /// <param name="strategy">is text strategy</param> /// <param name="image">is the image to be draw upon</param> /// <param name="offset">offsets the text (typically used for shadows)</param> /// <param name="textContext">is text context</param> /// <returns>true if successful</returns> public static bool DrawTextImage( ITextStrategy strategy, ref System.Windows.Media.Imaging.WriteableBitmap image, System.Windows.Point offset, TextContext textContext, System.Windows.Media.Matrix mat) { if (strategy == null || image == null || textContext == null) { return(false); } RenderTargetBitmap bmp = new RenderTargetBitmap((int)(image.Width), (int)(image.Height), 96, 96, PixelFormats.Pbgra32); DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); MatrixTransform mat_trans = new MatrixTransform(); mat_trans.Matrix = mat; drawingContext.PushTransform(mat_trans); drawingContext.DrawImage(image, new Rect(0.0, 0.0, image.Width, image.Height)); bool bRet = strategy.DrawString(drawingContext, textContext.fontFamily, textContext.fontStyle, textContext.fontWeight, textContext.nfontSize, textContext.pszText, new System.Windows.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y), textContext.ci); drawingContext.Pop(); drawingContext.Close(); bmp.Render(drawingVisual); image = new System.Windows.Media.Imaging.WriteableBitmap(bmp); return(bRet); }
public static bool DrawTextImage( ITextStrategy strategy, CanvasRenderTarget image, Point offset, CanvasTextLayout text_layout) { if (strategy == null || image == null || text_layout == null) { return(false); } using (CanvasDrawingSession ds = image.CreateDrawingSession()) { strategy.DrawString(ds, text_layout, (float)offset.X, (float)offset.Y); } return(true); }
public static CanvasRenderTarget GenMask( ITextStrategy strategy, int width, int height, Point offset, CanvasTextLayout text_layout) { if (strategy == null || text_layout == null) { return(null); } CanvasRenderTarget offscreen = GenImage(width, height, Color.FromArgb(0, 0, 0, 0)); using (CanvasDrawingSession ds = offscreen.CreateDrawingSession()) { strategy.DrawString(ds, text_layout, (float)offset.X, (float)offset.Y); } return(offscreen); }
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; }
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; }
/// <summary> /// Generate mask image of the text strategy. /// </summary> /// <param name="strategy">is text strategy</param> /// <param name="width">is the mask image width</param> /// <param name="height">is the mask image height</param> /// <param name="offset">offsets the text (typically used for shadows)</param> /// <param name="textContext">is text context</param> /// <returns>a valid mask image if successful</returns> public static System.Windows.Media.Imaging.WriteableBitmap GenMask( ITextStrategy strategy, int width, int height, System.Windows.Point offset, TextContext textContext, System.Windows.Media.Matrix mat) { if (strategy == null || textContext == null) return null; RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32); DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); MatrixTransform mat_trans = new MatrixTransform(); mat_trans.Matrix = mat; drawingContext.PushTransform(mat_trans); strategy.DrawString(drawingContext, textContext.fontFamily, textContext.fontStyle, textContext.fontWeight, textContext.nfontSize, textContext.pszText, new System.Windows.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y), textContext.ci); drawingContext.Pop(); drawingContext.Close(); bmp.Render(drawingVisual); return new System.Windows.Media.Imaging.WriteableBitmap(bmp); }
/// <summary> /// Draw outline on image /// </summary> /// <param name="strategy">is text strategy</param> /// <param name="image">is the image to be draw upon</param> /// <param name="offset">offsets the text (typically used for shadows)</param> /// <param name="textContext">is text context</param> /// <returns>true if successful</returns> public static bool DrawTextImage( ITextStrategy strategy, ref System.Windows.Media.Imaging.WriteableBitmap image, System.Windows.Point offset, TextContext textContext, System.Windows.Media.Matrix mat) { if (strategy == null || image == null || textContext == null) return false; RenderTargetBitmap bmp = new RenderTargetBitmap((int)(image.Width), (int)(image.Height), 96, 96, PixelFormats.Pbgra32); DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); MatrixTransform mat_trans = new MatrixTransform(); mat_trans.Matrix = mat; drawingContext.PushTransform(mat_trans); drawingContext.DrawImage(image, new Rect(0.0, 0.0, image.Width, image.Height)); bool bRet = strategy.DrawString(drawingContext, textContext.fontFamily, textContext.fontStyle, textContext.fontWeight, textContext.nfontSize, textContext.pszText, new System.Windows.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y), textContext.ci); drawingContext.Pop(); drawingContext.Close(); bmp.Render(drawingVisual); image = new System.Windows.Media.Imaging.WriteableBitmap(bmp); return bRet; }