Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void DrawText(String text, String path)
- {
- BitmapImage bi = new BitmapImage();
- bi.BeginInit();
- bi.UriSource = new Uri(@"E:\Hulk.gif", UriKind.RelativeOrAbsolute);
- bi.EndInit();
- string sText = "This is a text";
- int nTextHeight = 60;
- DrawingVisual drawingVisual = new DrawingVisual();
- using (DrawingContext drawingContext = drawingVisual.RenderOpen())
- {
- drawingContext.DrawImage(bi, new Rect(0, 0, bi.Width, bi.Height));
- Rect rect = new Rect(0, bi.Height, bi.Width, nTextHeight);
- drawingContext.DrawRectangle(System.Windows.Media.Brushes.LightGray, new Pen(Brushes.Red, 2), rect);
- var formattedText = new System.Windows.Media.FormattedText(sText, System.Globalization.CultureInfo.InvariantCulture,
- FlowDirection.LeftToRight,
- new Typeface("Arial"), 12, System.Windows.Media.Brushes.Red);
- formattedText.TextAlignment = TextAlignment.Center;
- double nX = bi.Width / 2;
- double nY = bi.Height + nTextHeight / 2;
- System.Windows.Point pt = new System.Windows.Point(nX, nY - formattedText.Height / 2);
- drawingContext.DrawText(formattedText, pt);
- }
- RenderTargetBitmap bmp = new RenderTargetBitmap((int)bi.Width, (int)bi.Height + nTextHeight, 96, 96, PixelFormats.Pbgra32);
- bmp.Render(drawingVisual);
- GifBitmapEncoder gif = new GifBitmapEncoder();
- gif.Frames.Add(BitmapFrame.Create(bmp));
- using (System.IO.Stream stm = System.IO.File.Create(@"E:\Hulk_2.gif"))
- {
- gif.Save(stm);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement