如何在保存到文件中之前在要从WPF网络摄像头捕获图像的捕获图像中添加文本? [英] how to add text in captured image which is capturing image from WPF webcam before saving into files?
本文介绍了如何在保存到文件中之前在要从WPF网络摄像头捕获图像的捕获图像中添加文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用wpf网络摄像头捕获图片.我想在将每个图像保存到硬盘之前在每个图像上添加水印....
i m using wpf webcam for capturing picture.i want to add watermarking on every image before saving it into harddrive....
推荐答案
您可以使用RenderTargetBitmap http://msdn.microsoft.com/en-us/library/system .windows.media.imaging.rendertargetbitmap.aspx [ ^ ]
例如:
you can use RenderTargetBitmap http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx[^]
For example:
// background
BitmapSource bgImage = new BitmapImage(new Uri(bgImagePath, UriKind.Relative));
// RenderTargetBitmap
RenderTargetBitmap composeImage = new RenderTargetBitmap(bgImage.PixelWidth, bgImage.PixelHeight, bgImage.DpiX, bgImage.DpiY, PixelFormats.Default);
// signature
FormattedText signatureTxt = new FormattedText(signature, System.Globalization.CultureInfo.CurrentCulture,System.Windows.FlowDirection.LeftToRight,new Typeface(System.Windows.SystemFonts.MessageFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),50,System.Windows.Media.Brushes.White);
// render
double x2 = (bgImage.Width/2 - signatureTxt.Width) / 2;
double y2 = y + headerImage.Height + 20;
drawingContext.DrawText(signatureTxt, new System.Windows.Point(x2, y2));
drawingContext.Close();
composeImage.Render(drawingVisual);
// save file
JpegBitmapEncoder bitmapEncoder = new JpegBitmapEncoder();
bitmapEncoder.Frames.Add(BitmapFrame.Create(composeImage));
string savePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"\merged.jpg";
bitmapEncoder.Save(File.OpenWrite(Path.GetFileName(savePath)));
这篇关于如何在保存到文件中之前在要从WPF网络摄像头捕获图像的捕获图像中添加文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文