merging image

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 4
Reputation: diyana is an unknown quantity at this point 
Solved Threads: 0
diyana diyana is offline Offline
Newbie Poster

merging image

 
0
  #1
Aug 29th, 2007
hi i have created a code that allows images from 5 picboxes to merge together.
but i have a problem distinguishing them.
after merging, i would want to have different greyscale values for the images merged into one picbox.
my image is made up of black and white only. thus, the image of the black image(which are actually dots) to have different pixel value. BUT, it must still be a shade of black.

this is the code that i am working on:
  1. public Bitmap mergeImages(Bitmap[] images)
  2. {
  3. Bitmap mergedImg = new Bitmap(images[0].Width, images[0].Height);
  4.  
  5. for (int h = 0; h < mergedImg.Height; h++)
  6. {
  7.  
  8. for (int w = 0; w < mergedImg.Width; w++)
  9. {
  10.  
  11. Color c = images[0].GetPixel(w, h);
  12.  
  13. if (c.R == 255 && c.G == 255 && c.B == 255)
  14. {
  15. int index = 1;
  16. for (; index < images.Length; index++)
  17. {
  18. if (images[index].GetPixel(w, h) == c)
  19. continue;
  20. else
  21. break;
  22.  
  23. }
  24. if (index == images.Length)
  25. {
  26. //all the pixel in the same location in all images are all white
  27.  
  28. mergedImg.SetPixel(w, h, c);
  29. }
  30. else
  31. {
  32. //if not, set the color of the pixel to be black;
  33. Color c1 = Color.FromArgb(0, 0, 0);
  34. mergedImg.SetPixel(w, h, c1);
  35. }
  36. }
  37. else
  38. {
  39. Color c1 = Color.FromArgb(0, 0, 0);
  40. mergedImg.SetPixel(w, h, c1);
  41. }
  42. }
  43. }
  44. return mergedImg;
  45. }
pls help.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: merging image

 
0
  #2
Sep 24th, 2007
for those tasks, I recommend to use MATLAB it helps a lot and has a lot of built in algorithms and toolbox you can use, use its funcationality then make your work as dll and call it from C# application
Last edited by Ramy Mahrous; Sep 24th, 2007 at 7:27 pm.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 16
Reputation: gbertoli3 is an unknown quantity at this point 
Solved Threads: 0
gbertoli3 gbertoli3 is offline Offline
Newbie Poster

Re: merging image

 
0
  #3
Oct 19th, 2008
I was just trying to make the same thing. It took me a while but I got it.

Hope this helps
  1. /// <summary>
  2. /// Merges 4 Images into 1 Image.
  3. /// </summary>
  4. /// <param name="image1">The Image you want in the Top-Left Corner.</param>
  5. /// <param name="image2">The Image you want in the Top-Right Corner.</param>
  6. /// <param name="image3">The Image you want in the Bottom-Left Corner.</param>
  7. /// <param name="image4">The Image you want in the Bottom-Right Corner.</param>
  8. /// <returns>An Image of 4</returns>
  9. public Image MergeImages(Image image1, Image image2, Image image3, Image image4)
  10. {
  11. //Get the Width of All the Images
  12. Int32 width = image1.Width + image2.Width + image3.Width + image4.Width;
  13. //Get the Height of All the Images
  14. Int32 height = image1.Height + image2.Height + image3.Height + image4.Height;
  15. //Create a new Bitmap with the Width and Height
  16. Bitmap bitmap = new Bitmap(width, height);
  17.  
  18. //Get All of the x Pixels
  19. for (int w = 0; w < image1.Width; w++)
  20. {
  21. //Get All of the Y Pixels
  22. for (int h = 0; h < image1.Height; h++)
  23. {
  24. //Create a new Bitmap from image1
  25. Bitmap image = new Bitmap(image1);
  26. //Set the Cooresponding Pixel
  27. bitmap.SetPixel(w, h, image.GetPixel(w, h));
  28. }
  29. }
  30. //Get All of the x Pixels
  31. for (int w = 0; w < image2.Width; w++)
  32. {
  33. //Get All of the Y Pixels
  34. for (int h = 0; h < image2.Height; h++)
  35. {
  36. //Create a new Bitmap from image2
  37. Bitmap image = new Bitmap(image2);
  38. //Set the Cooresponding Pixel
  39. bitmap.SetPixel(image.Width + w, h, image.GetPixel(w, h));
  40. }
  41. }
  42. //Get All of the x Pixels
  43. for (int w = 0; w < image3.Width; w++)
  44. {
  45. //Get All of the Y Pixels
  46. for (int h = 0; h < image3.Height; h++)
  47. {
  48. //Create a new Bitmap from image3
  49. Bitmap image = new Bitmap(image3);
  50. //Set the Cooresponding Pixel
  51. bitmap.SetPixel(w, image.Height + h, image.GetPixel(w, h));
  52. }
  53. }
  54. //Get All of the x Pixels
  55. for (int w = 0; w < image4.Width; w++)
  56. {
  57. //Get All of the Y Pixels
  58. for (int h = 0; h < image4.Height; h++)
  59. {
  60. //Create a new Bitmap from image4
  61. Bitmap image = new Bitmap(image4);
  62. //Set the Cooresponding Pixel
  63. bitmap.SetPixel(image.Width + w, image.Height + h, image.GetPixel(w, h));
  64. }
  65. }
  66.  
  67. //Return the new Bitmap
  68. return bitmap;
  69. }
Last edited by gbertoli3; Oct 19th, 2008 at 7:59 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC