private void HandleImageBtn_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(dlg.FileName)) { MessageBox.Show("请先选择源文件"); } int sharpness = 90; if (!string.IsNullOrEmpty(SharpnessText.Text)) { sharpness = Convert.ToInt32(SharpnessText.Text); } var currentDir = Environment.CurrentDirectory; var outputPath = System.IO.Path.Combine(currentDir, "temp.jpg"); var fileInfo = new FileInfo(dlg.FileName); //using var image = SixLabors.ImageSharp.Image.Load(File.OpenRead(fileInfo.FullName)); //image.Clone(x => x.BackgroundColor(Rgba32.Transparent)); //image.SaveAsJpeg(outStream, new JpegEncoder //{ // Quality = sharpness //}); //outStream.Seek(0, SeekOrigin.Begin); var helper = new ImageProcess(); var outStream = File.OpenRead(fileInfo.FullName); var stream = helper.AddWatermark(outStream, File.OpenRead("./test.png"), Position.TopLeft, 200, 80); stream.Position = 0; var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.StreamSource = stream; bitmapImage.EndInit(); OutputImage.Source = bitmapImage; MessageBox.Show("处理完成,你可以点击保存选择将图片另存为"); }
public MainWindow() { InitializeComponent(); imgProcess = new ImageProcess(); }