合并图像的问题c# [英] Problem with merging images c#

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

问题描述

我正在尝试使用Windows表单aplication c#合并多个图像。



这里是我的代码:

I am trying to merge multiple images using Windows form aplication c#.

here is my code:

private void btn_save_image_Click(object sender, EventArgs e)
       {
           Graphics g = Graphics.FromImage(loaded_image); // "loaded_image" is the initial image

           g.DrawImage(pb.Image, pb.Location); // Drawing "pb" in initial image 

           SaveFileDialog sf = new SaveFileDialog();
           if (sf.ShowDialog() == DialogResult.OK)
           {
               loaded_image.Save(sf.FileName + ".jpg"); // saving the image

           }
       }





问题是:



保存图像时图像pb不在我保留初始图像的地方。



示例:我的应用程序我在狗头上添加了一个帽子的图像。当我保存并打开.jpg文件时,帽子的图像不在狗的头上 - 它在狗的耳朵里。



我该如何解决?



The problem is:

When the image is saved the image "pb" isn't in the place where i kept it in initial image.

Example: I my application I added a image of a cap over a dog's head. When i save it and open the .jpg file then, the image of cap isn't in dog's head- it's in dog's ear.

How should i fix it ?

推荐答案

我假设您正在屏幕上移动图像屏幕上有一个单独的图像?



你需要开始查看位置属性,并且它是关于 - 以及正在进行的任何缩放显示的图像。



猜测,您的loaded_image位于PictureBox中,并且正在缩放以适合该框:所以它看起来像封面适合但实际上该位置是相对于显示的缩放图像,而不是您稍后将其绘制的原始尺寸图像。
I assume that you are moving an image on screen over a separate image on screen?

You need to start looking at the Location property, and whit it is in respect of - and also at any scaling which is being done to the displayed image(s).

At a guess, your "loaded_image" is in a PictureBox, and is being scaled to fit the box: so it looks like the "cap fits" but in reality the location is relative to the scaled image on display and not the original-sized image you are drawing it onto later.


这篇关于合并图像的问题c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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