Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i m using wpf webcam for capturing picture.i want to add watermarking on every image before saving it into harddrive....
Posted
Updated 24-Oct-13 0:35am
v2
Comments
Nitin Gupta1 24-Oct-13 6:33am    
if anybody knows the way
pls tell me.

1 solution

you can use RenderTargetBitmap http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx[^]

For example:
C#
// 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)));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900