Hello Guys

I am looking for some code,that can help me to build a C# method that can generate a photo mosaic (a big picture that is build up from other pictures) but really i dont have idea how can i do this. :S

Thanks for all your help
:D

Recommended Answers

All 5 Replies

No one is ever going to do this for you. Show some effort, anyone can say they have no idea what to do.

Show us something we can help you with.

Just Google the solution you will find it. I even found this in one search:
http://photohandler.codeplex.com

You could also search in the direction of ASCII art. Assign some fotos to ascii chars and get started. Looking forward, what you come up with.

i still trying to figure out how to do this i get this code

public static Bitmap MakeGrayscale(Bitmap original)
        {
            //make an empty bitmap the same size as original
            Bitmap newBitmap = new Bitmap(original.Width, original.Height);

            for (int i = 0; i < original.Width; i++)
            {
                for (int j = 0; j < original.Height; j++)
                {
                    //get the pixel from the original image
                    Color originalColor = original.GetPixel(i, j);

                    //create the grayscale version of the pixel
                    int grayScale = (int)((originalColor.R * .3) + (originalColor.G * .59)
                        + (originalColor.B * .11));


                    //Random Colors 
                        Random generator = new Random(DateTime.Now.Millisecond);
                        int red = generator.Next(256);
                        int green = generator.Next(256);
                        int blue = generator.Next(256);

                    //create the color object
                    Color newColor = Color.FromArgb(grayScale, grayScale, grayScale);
                    Color newCol =   Color.FromArgb(red, green, blue);


                    //set the new image's pixel to the grayscale version
                    newBitmap.SetPixel(i, j, newColor);
                }
            }

            return newBitmap;
            // code from: http://tech.pro/tutorial/660/csharp-tutorial-convert-a-color-image-to-grayscale
        }



    that convert an image full color to gray scale but need figure out how to insert and image on each pixel inside of switch the color.

What your asking isn't that easy.

I mean you could insert any photo you want, but that doesn't guarantee the color you will get.

Now I have a theory how this might work, it's a long shot, but you could give it a try. First you have a collection of photos you want to use for the mosaic. Then read in each image at a time, read each pixel, get the color code of that pixel, and then create an average number of all these pixels (so you get an average color).

This could take some time, so my advice, read in the collection at once, and store the data in an object with the file name and average color value.

Then when you want to convert an image, you get the color of the pixel, and then look through your collection of images, seeing which one has an average pixel color closes to the one you have. You might also want to put in some variables to prevent the same photo being used, or allow it to only be used if it's (x,y) amount of pixels from another pixel that used the same image.

AGAIN, this is purely a theory I came up with on how to do it. You'd have to try it (actually, I think I might as I feel this could work rather well). The only problem I see, you'll need a big collection of images to use. Also all your images will probably have to resizes to the same size, and the mosaic itself, will be rather huge, cause you won't want to downsize the collection of images used to color down to 1 pixel

Old topic, but I think a good approach would be to get a large collection of images, and you resize each image to 1 pixel. Once you have done this then the image has an absolute final color, that being whatever color those images are. This can be used as a 1:1 map that you can use to map each pixel of your larger picture to an individual photo. If you want your larger image to be 100 pictures wide by 100 pictures tall, then you resize it to 100px. Then you construct your image.

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.