Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to merge multiple images using Windows form aplication c#.

here is my code:
C#
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

           }
       }


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 ?
Posted

1 solution

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.
 
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