# 图片相似度计算：谁可以用代码帮我实现一个功能，我已经实现了部分简单的，后面的知识面不够，写不下去了

0
[已关闭问题] 关闭于 2012-04-28 09:58

` 1     class LikeImage 2     { 3         public void Compare(Image i1 ,Image i2) 4         { 5             Image i8x8 = get8x8Image(i1); 6             Image igray = getGrayImage(i8x8); 7             i8x8.Save("8.jpg"); 8             igray.Dispose(); 9             i8x8.Dispose();10         }11 12         ///<summary>13 /// 图片灰度处理14 ///</summary>15 ///<param name="i"></param>16 ///<returns></returns>17         Image getGrayImage(Image i)18         {19             Bitmap bmPhoto = new Bitmap(i);20             Graphics g = Graphics.FromImage(bmPhoto);21 22             Color currentColor;23             int r;24             for (int w = 0; w < bmPhoto.Width; w++)25             {26                 for (int h = 0; h < bmPhoto.Height; h++)27                 {28                     currentColor = bmPhoto.GetPixel(w, h);29                     r = (currentColor.R + currentColor.G + currentColor.B) / 3;30                     31                     bmPhoto.SetPixel(w, h, Color.FromArgb(r, r, r));32                 }33             }34            35             g.Dispose();36             return bmPhoto;37         }38 39         ///<summary>40 /// 获得 8*8 的缩略图41 ///</summary>42 ///<param name="i"></param>43 ///<returns></returns>44         Image get8x8Image(Image i)45         {46             int size = 8;47             int _x, _y,_size;48 49             if (i.Height > i.Width)50             {51                 _size = i.Width;      52                 _x = 0;53                 _y = (int)Math.Round((double)(i.Height - _size) / 2, 0);54             }55             else56             {57                 _size = i.Height;58                 _x = (int)Math.Round((double)(i.Width - _size) / 2, 0);59                 _y = 0;60             }61 62             Bitmap bmPhoto = new Bitmap(size, size, PixelFormat.Format24bppRgb);63             bmPhoto.SetResolution(i.HorizontalResolution, i.VerticalResolution);64             Graphics g = Graphics.FromImage(bmPhoto);65             g.DrawImage(i,66                 new Rectangle(0, 0, size, size),          ///它指定所绘制图像的位置和大小。67                 new Rectangle(_x, _y, _size, _size), ///它指定 image 对象中要绘制的部分。68                 GraphicsUnit.Pixel69             );70             g.Dispose();71             return bmPhoto;72         }73     }`

fun5 | 初学一级 | 园豆：4

0

1500019596

您需要登录以后才能回答，未注册用户请先注册