Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i need a solution in C# to merge two separate images without merging a line between them at they merge..


Problem pic

just merg 2 images, a line show b/w them because of color difference, i want to disappear that line,

CODE:

C#
private Bitmap Merge_Images(Bitmap bmp_1, Bitmap bmp_2)
       {
           if (bmp_1 == null || bmp_2 == null)
               return null;


     int bmp_1_Height, bmpWidth, bmp_2_Height;
               bmpWidth = bmp_1.Width;
               bmp_1_Height = bmp_1.Height;

               bmp_2_Height = bmp_2.Height;

               int firstMatchedRow = bmp_1.Height;

               byte[,] bmp2_first2rows = new byte[3 * bmpWidth, 2];


               Bitmap bmp = new Bitmap(bmpWidth, bmp_1_Height + bmp_2_Height);
               Graphics g = Graphics.FromImage(bmp);
               Rectangle RectDst = new Rectangle(0, 0, bmpWidth, bmp_1_Height);
               Rectangle RectSrc;
               g.DrawImage(bmp_1, RectDst, RectDst, GraphicsUnit.Pixel);
               RectDst = new Rectangle(0, bmp_1_Height, bmpWidth, bmp_2_Height);
               RectSrc = new Rectangle(0, 0, bmpWidth, bmp_2_Height);
               g.DrawImage(bmp_2, RectDst, RectSrc, GraphicsUnit.Pixel);

               int recx,recy,recw,rech;
     rech=10;
     recw=bmpWidth;

     recx=0;
     recy=firstMatchedRow-5;

               Rectangle r1 = new Rectangle(recx,recy, recw, rech);

               //Bitmap b2 = Blur(bmp, r1, 5);

               /// pictureBox4.Image = bmp;
               return bmp;

       }
Posted
Updated 13-Dec-14 1:15am
v2
Comments
OriginalGriff 13-Dec-14 5:16am    
And?
What have you tried?
Where are you stuck?
Member 10756761 13-Dec-14 7:20am    
Problem pic : https://social.msdn.microsoft.com/Forums/vstudio/en-US/efe0abc4-27ef-4d09-a56a-d4a44527bb35/how-to-merge-two-images-without-merging-their-borders-pointing-in-picture?forum=csharpgeneral

just merg 2 images, a line show b/w them because of color difference, i want to disappear that line,

Question updated with code

Have a look here: Merging Images in .NET[^]

More, you can find here: SearchBox[^]
 
Share this answer
 
Comments
[no name] 13-Dec-14 6:43am    
First link I like very much. Short and to the point. Second I did not read.
My 5.
Maciej Los 13-Dec-14 6:50am    
Thank you, Bruno ;)
This can be done using the Graphics class in the System.Drawing namespace. First, you have load the two images you want to merge. Then, you create a new empty Bitmap where the width is the sum of the two widths of the loaded images, and the height is the maximum height of those images. After doing that, create a Graphics from that Bitmap and use the DrawImage method to draw the image on the graphics. At the end, the new Bitmap will contain a merged image, which you'll need to save. The code also contains a few Dispose() calls, which releases all used resources by those objects. Note: don't dispose an object if you need it later.
C#
Image img1 = Image.FromFile("part1.png");
Image img2 = Image.FromFile("part2.png");
int newHeight = Math.Max(img1.Height, img2.Height);
int newWidth = img1.Width + img2.Width;
Bitmap merged = new Bitmap(newWidth, newHeight);
Graphics gr = Graphics.FromImage(merged);
gr.DrawImage(img1, new Point(0, 0));
gr.DrawImage(img2, new Point(img1.Width, 0));
gr.Dispose();
merged.Save("result.png", ImageFormat.Png); // or another format
img1.Dispose();
img2.Dispose();
merged.Dispose();
 
Share this answer
 
v2
Whether two images can be merged (composited) in a way that no unusual boundary (artifacts) will appear in the merged image, depends entirely on the images you are attempting to merge !

And, I propose to you that ... unless you are in the fortunate position of having images with the same background, and lighting, and focus, etc. ... there's no way you can "automate" that: that it will take a skilled human operator making decisions on where to crop each image to get something that's doesn't look like patched-up fender before it's repainted :)

Adobe has world-class computer scientists who've worked for a very long-time to develop the current "Content Aware" Fill, Scale, Heal, Patch, and Move, tools in PhotoShop. The algorithms those tools use are extremely complex !

And, even with those tools: in the current PhotoShop CC (which I use), as good as they are, most of the time it will take further processing by the person using PhotoShop to tweak the images before they are merged, and after they are merged. Typically you might do pre-merge color palette correction, contrast and brightness correction, and post-merge, perform some combination of sharpening/blur/anti-alias (feathering), and apply other filters.

I'm not saying you can't create a tool that's useful for simple merges; just advising you that this is a complex problem domain, and you will be constrained by the images you have to work with.

On a practical basis, I'd want to see a user-interface that, at minimum:

1. showed both images, presented summary information about them: size, bit-depth, any color-palette information in the EXIF (sRGB ? or ???).

2. let you convert either or both to a bit-depth and color palette you chose.

3. let you crop by some mouse-action ui, or by numeric entry, either, or both, images

4. let you adjust relative contrast, and brightness.

5. let you specify final output size

6. preview final output with 'undo

I know you will learn a lot from this wonderful opportunity to challenge yourself !
 
Share this answer
 
v2

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