如我有一张大图片A.jpg
然后我在这个图片中用矩形截取了一片图片保存为b.jpg
然后现在用C#程序
如何得出
图片b.jpg在a.jpg的x1和y1的位置?谢谢

解决方案 »

  1.   

    先把图片读到PictureBox控件中。
    然后,PictureBox_MouseDown事件。画矩形。Point point = new Point(e.X, e.Y);
      

  2.   

    偶觉得应该采用模糊特征方式。。
    ----------------
    不用。。因为我的图片的小图是一定和里面的一小部分一样的
    所以我想用byte数组的方法,但对比不到public class Location
        {
            public int X1 { get; set; }
            public int Y1 { get; set; }
            public int X2 { get; set; }
            public int Y2 { get; set; }
        }    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                var imgbyte = imageToByteArray("C:\\1.jpg");
                var subtyte = imageToByteArray("C:\\2.jpg");
                var list = new List<Location>();
                byte a, b;
                for (int i = 0; i <= imgbyte.Length - 1; i++)
                {
                    a = imgbyte[i];
                    b = subtyte[0];
                    if (imgbyte[i] == subtyte[0])
                    {
                        //如果找到再找子是相对应
                        for (int j = 1; j <= subtyte.Length - 1; j++)
                        {
                            a = imgbyte[i + j];
                            b = subtyte[j];
                            if (imgbyte[i + j] == subtyte[j])
                            {
                                if (j == subtyte.Length - 1)
                                {
                                    //说明一样
                                    list.Add(new Location() { X1 = i, X2 = i + j });
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                foreach (var item in list)
                {
                    System.Console.WriteLine("X1 = " + item.X1 + ", X2 = " + item.X2);
                }
            }        /// <summary>
            /// 图片转为Byte字节数组
            /// </summary>
            /// <param name="FilePath">路径</param>
            /// <returns>字节数组</returns>
            private byte[] imageToByteArray(string FilePath)
            {
                using (MemoryStream ms = new MemoryStream())
                {                using (Image imageIn = Image.FromFile(FilePath))
                    {                    using (Bitmap bmp = new Bitmap(imageIn))
                        {
                            bmp.Save(ms, imageIn.RawFormat);
                        }                }
                    return ms.ToArray();
                }
            }
            /// <summary>
            /// 字节数组生成图片
            /// </summary>
            /// <param name="Bytes">字节数组</param>
            /// <returns>图片</returns>
            private Image byteArrayToImage(byte[] Bytes)
            {
                using (MemoryStream ms = new MemoryStream(Bytes))
                {
                    Image outputImg = Image.FromStream(ms);
                    return outputImg;
                }
            }
        }
      

  3.   

    jpg是有损压缩的,你这样是对比不到的。
      

  4.   

    谁能帮我解决一下问题谢谢 地址(http://topic.csdn.net/u/20110608/17/ea387470-0398-4bb3-b92a-68a37f63cd16.html?31016)
      

  5.   

    这样的两幅jpg图片就算是同样的部分也保证不了100%一样。