日期:2014-05-17  浏览次数:20866 次

在判断图形A是否在图形B里存在 中,有个新手不懂的问题,请指教
 C# 判断图形A是否在图形B里存在 并返回所在位置的坐标


做了下测试

 

  Bitmap Image1 = (Bitmap)Image.FromFile(@"c:/1.BMP");


            Bitmap Image2 = Image1.Clone(new Rectangle(20, 20, 50, 50), Image1.PixelFormat);


            Point _Point= Zgke.MyImage.Panit.MyPanit.GetImageContains(Image1, Image2,0);


            MessageBox.Show(_Point.ToString());

 

返回的坐标是20,20

 

 

 

 

下面是全部代码

 
   /// <summary>
        /// 判断图形里是否存在另外一个图形 并返回所在位置
        /// </summary>
        /// <param name="p_SourceBitmap">原始图形</param>
        /// <param name="p_PartBitmap">小图形</param>
        /// <param name="p_Float">溶差</param>
        /// <returns>坐标</returns>
        public static Point GetImageContains(Bitmap p_SourceBitmap, Bitmap p_PartBitmap,int p_Float)
        {
            int _SourceWidth = p_SourceBitmap.Width;
            int _SourceHeight = p_SourceBitmap.Height;

            int _PartWidth = p_PartBitmap.Width;
            int _PartHeight = p_PartBitmap.Height;

            Bitmap _SourceBitmap = new Bitmap(_SourceWidth, _SourceHeight);
            Graphics _Graphics = Graphics.FromImage(_SourceBitmap);
            _Graphics.DrawImage(p_SourceBitmap, new Rectangle(0, 0, _SourceWidth, _SourceHeight));
            _Graphics.Dispose();
            BitmapData _SourceData = _SourceBitmap.LockBits(new Rectangle(0, 0, _SourceWidth, _SourceHeight), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);