【问题标题】:How to Mirror An Image [duplicate]如何镜像图像[重复]
【发布时间】:2015-10-26 05:17:19
【问题描述】:

这是我的原图,

我想镜像它并让它看起来像这样,

我想镜像我的图像,以便原始图像和镜像图像并排显示。唯一的问题是我不知道如何扩展我的原始图像的范围以便在它旁边添加它的镜像。

使用我的代码(如下)我已经成功地创建了镜像,只是我不能让原始图像和镜像图像并排显示。

我的代码,

        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是保存原图的变量

【问题讨论】:

    标签: c# image


    【解决方案1】:

    第 1 步:镜像图像。 为此,应用一个负 sacaletransform。喜欢

    new ScaleTransform() { ScaleX = -1 };

    然后并排合并两个图像。 可以看这里,怎么合并Two images

    这是另一种方式:

            //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;
    

    【讨论】:

      【解决方案2】:

      这就是BitMap的实现方式,您可以从图形中绘制图像,然后用修改后的图形对象重新绘制图形对象。

      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;
          }
      

      【讨论】:

      • 这看起来很慢。
      • 如果你应该使用LockBits()进行直接操作
      猜你喜欢
      • 2022-11-18
      • 2016-04-26
      • 2012-09-08
      • 2017-06-24
      • 2019-08-10
      • 1970-01-01
      • 2018-08-29
      • 2012-01-14
      • 1970-01-01
      相关资源
      最近更新 更多