在WPF中叠加/合并图像 [英] Overlaying/merging Images in WPF

查看:127
本文介绍了在WPF中叠加/合并图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的表单上有两个图像,一个是.jpg,另一个是.png.我正在做的就是覆盖它们,以尝试创建一张图像,然后将其保存到文件中.我在网上做了很多搜索,但似乎找不到简单的方法来做.我有下面的代码,我认为这两个代码已合并为MyImage.然后如何将其保存到.jpg文件?


另外,有人知道这样做的好方法吗?



Hi all,

I have two images on my form, one is a .jpg the other is a .png. What I''m doing is overlaying them to try and create one image that I can then save to a file. I''ve done a lot of searching on the net but can''t seem to find a simple way to do it. I''ve got the code below which I think has amalgamated the two images into MyImage. How can I then save this to a .jpg file?


Alternativelyy, does anyone know of a nice easy way to do this?



public static void Overlay(ImageSource first, ImageSource second)
  {

   ((BitmapFrame)first).Decoder.ToString();

   var group = new DrawingGroup();
   group.Children.Add(new ImageDrawing(new BitmapImage(new Uri(((BitmapFrame)first).Decoder.ToString(), UriKind.Absolute)), 
    new Rect(0, 0, first.Width, first.Height)));
   group.Children.Add(new ImageDrawing(new BitmapImage(new Uri(((BitmapFrame)second).Decoder.ToString(), UriKind.Absolute)),
    new Rect(0, 0, first.Width, first.Height)));

   Image MyImage = new Image();
   
   MyImage.Source = new DrawingImage(group);

  }





谢谢大家,



Jib





Thanks all,



Jib

推荐答案

您将需要将图像投射到位图,然后将文件保存-在对象上有一个Save()方法供您使用.

鲍勃·鲍威尔 [
You''ll want to cast the image to a Bitmap and then save the file out - there''s a Save() method for you on the object.

Bob Powell[^] has a ton of info on image manipulation that you will find very helpful. A simple scan of his work will find you several ways to do this.

Cheers.


这取决于您要尝试执行的操作.您可以尝试将图像彼此叠放并调整顶部图像的不透明度以显示下面的图像(这类似于应用水印).
It depends on what exactly you''re trying to do. You can try placing the images over each other and adjusting the opacity of the top image to show the image below (this would be similar to applying a watermark).


这篇关于在WPF中叠加/合并图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆