3

This is my original image, enter image description here

I want to mirror it and have it appear like this, enter image description here

I want to mirror my image so that the original and the mirrored image appear side by side. The only thing is that I don't know how to extend the range of my original image in order to add its mirrored image right beside it.

Using my code (below) I have managed to do create the mirrored image, only I can't make both the original and the mirrored appear side by side.

My code,

        int Height = TransformedPic.GetLength(0);
        int Width = TransformedPic.GetLength(1);

        for (int i = 0; i < Height / 2; i++)
        {
            for (int j = 0; j < Width; j++)
            {
                var Temporary = TransformedPic[i, j];
                TransformedPic[i, j] = TransformedPic[Height - 1 - i, j];
                TransformedPic[Height - 1 - i, j] = Temporary;
            }
        }

TransformedPic is the variable in which the original image is saved under

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Cool Cat
  • 127
  • 2
  • 9

2 Answers2

4

Step 1 : Mirror an Image. To do this apply a negative sacaletransform. Like

new ScaleTransform() { ScaleX = -1 };

Then merge two image side by side. you can see it here, how you can merge Two images.

Here is another way :

        //Get Your Image from Picturebox
        Bitmap image1 = new Bitmap(pictureBox1.Image);
        //Clone it to another bitmap
        Bitmap image2 = (Bitmap)image1.Clone();
        //Mirroring
        image2.RotateFlip(RotateFlipType.RotateNoneFlipX);

        //Merge two images in bitmap image,
        Bitmap bitmap = new Bitmap(image1.Width + image2.Width, Math.Max(image1.Height, image2.Height));
        using (Graphics g = Graphics.FromImage(bitmap))
        {
            g.DrawImage(image1, 0, 0);
            g.DrawImage(image2, image1.Width, 0);
        }
        //Show them in a picturebox
        pictureBox2.Image = bitmap;
Community
  • 1
  • 1
Abdur Rahim
  • 3,975
  • 14
  • 44
  • 83
1

This is how it's done with a BitMap, you can draw the image from the graphics and redraw the graphics object with the modified one.

public Bitmap MirrorImage(Bitmap source)
    {
        Bitmap mirrored = new Bitmap(source.Width, source.Height);
        for(int i = 0; i < source.Height; i++)
            for(int j = 0; j < source.Width; j++)
                mirrored.SetPixel(i, j, source.GetPixel(source.Width - j - 1, i);
        return mirrored;
    }
Rakin
  • 1,271
  • 14
  • 30