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:

public Bitmap mergeImages(Bitmap[] images)
        {
            Bitmap mergedImg = new Bitmap(images[0].Width, images[0].Height);

            for (int h = 0; h < mergedImg.Height; h++)
            {

                for (int w = 0; w < mergedImg.Width; w++)
                {

                    Color c = images[0].GetPixel(w, h);

                    if (c.R == 255 && c.G == 255 && c.B == 255)
                    {
                        int index = 1;
                        for (; index < images.Length; index++)
                        {
                            if (images[index].GetPixel(w, h) == c)
                                continue;
                            else
                                break;

                        }
                        if (index == images.Length)
                        {
                            //all the pixel in the same location in all images are all white

                            mergedImg.SetPixel(w, h, c);
                        }
                        else
                        {
                            //if not, set the color of the pixel to be black;
                            Color c1 = Color.FromArgb(0, 0, 0);
                            mergedImg.SetPixel(w, h, c1);
                        }
                    }
                    else
                    {
                        Color c1 = Color.FromArgb(0, 0, 0);
                        mergedImg.SetPixel(w, h, c1);
                    }
                }
            }
            return mergedImg;
        }

pls help.

Recommended Answers

All 2 Replies

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

I was just trying to make the same thing. It took me a while but I got it.

Hope this helps

/// <summary>
        /// Merges 4 Images into 1 Image.
        /// </summary>
        /// <param name="image1">The Image you want in the Top-Left Corner.</param>
        /// <param name="image2">The Image you want in the Top-Right Corner.</param>
        /// <param name="image3">The Image you want in the Bottom-Left Corner.</param>
        /// <param name="image4">The Image you want in the Bottom-Right Corner.</param>
        /// <returns>An Image of 4</returns>
        public Image MergeImages(Image image1, Image image2, Image image3, Image image4)
        {
            //Get the Width of All the Images
            Int32 width = image1.Width + image2.Width + image3.Width + image4.Width;
            //Get the Height of All the Images
            Int32 height = image1.Height + image2.Height + image3.Height + image4.Height;
            //Create a new Bitmap with the Width and Height
            Bitmap bitmap = new Bitmap(width, height);

            //Get All of the x Pixels
            for (int w = 0; w < image1.Width; w++)
            {
                //Get All of the Y Pixels
                for (int h = 0; h < image1.Height; h++)
                {
                    //Create a new Bitmap from image1
                    Bitmap image = new Bitmap(image1);
                    //Set the Cooresponding Pixel
                    bitmap.SetPixel(w, h, image.GetPixel(w, h));
                }
            }
            //Get All of the x Pixels
            for (int w = 0; w < image2.Width; w++)
            {
                //Get All of the Y Pixels
                for (int h = 0; h < image2.Height; h++)
                {
                    //Create a new Bitmap from image2
                    Bitmap image = new Bitmap(image2);
                    //Set the Cooresponding Pixel
                    bitmap.SetPixel(image.Width + w, h, image.GetPixel(w, h));
                }
            }
            //Get All of the x Pixels
            for (int w = 0; w < image3.Width; w++)
            {
                //Get All of the Y Pixels
                for (int h = 0; h < image3.Height; h++)
                {
                    //Create a new Bitmap from image3
                    Bitmap image = new Bitmap(image3);
                    //Set the Cooresponding Pixel
                    bitmap.SetPixel(w, image.Height + h, image.GetPixel(w, h));
                }
            }
            //Get All of the x Pixels
            for (int w = 0; w < image4.Width; w++)
            {
                //Get All of the Y Pixels
                for (int h = 0; h < image4.Height; h++)
                {
                    //Create a new Bitmap from image4
                    Bitmap image = new Bitmap(image4);
                    //Set the Cooresponding Pixel
                    bitmap.SetPixel(image.Width + w, image.Height + h, image.GetPixel(w, h));
                }
            }
            
            //Return the new Bitmap
            return bitmap;
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.