因为自己不是搞C的代码中,很多函数都不明白什么意思。麻烦大家解释下。
VOID OnPaint(HDC hdc)
{
   Graphics graphics(hdc);   Bitmap b(L"Calvin.jpg");
   Bitmap* b2;   INT iWidth = b.GetWidth();
   INT iHeight = b.GetHeight();   Rect rect(0,0,iWidth,iHeight);
   b2 = b.Clone(rect,PixelFormat24bppRGB);   
   BitmapData bmData;
   BitmapData bmData2;   b.LockBits(&rect,ImageLockModeRead | ImageLockModeWrite,
              PixelFormat24bppRGB,&bmData);
   b2->LockBits(&rect,ImageLockModeRead |ImageLockModeWrite,
                PixelFormat24bppRGB,&bmData2);
   
   int stride = bmData.Stride;   unsigned char * p = (unsigned char *)bmData.Scan0;
   unsigned char * p2 = (unsigned char *)bmData2.Scan0;
   
   
   int nOffset = stride - iWidth*3; 
   int nWidth = iWidth * 3;   int nPixel = 0, nPixelMax = 0;   p += stride;
   p2 += stride;
   int nThreshold = 0;
   
  for(int y=1;y < (iHeight-1);++y)
  {
     p += 3;
     p2 += 3;     for(int x=3; x < (nWidth-3); ++x )
     {  

        nPixelMax = abs((p2 - stride + 3)[0] - (p2+stride-3)[0]);
        nPixel = abs((p2 + stride + 3)[0] - (p2 - stride - 3)[0]);
        if (nPixel>nPixelMax)
           nPixelMax = nPixel;        nPixel = abs((p2 - stride)[0] - (p2 + stride)[0]);
        if (nPixel>nPixelMax)
            nPixelMax = nPixel;        nPixel = abs((p2+3)[0] - (p2 - 3)[0]);
        if (nPixel>nPixelMax)
            nPixelMax = nPixel;        if (nPixelMax < nThreshold) 
    nPixelMax = 0;

        p[0] = (byte) nPixelMax;        ++ p;
        ++ p2;
            
     }     p += 3 + nOffset;
     p2 += 3 + nOffset;
}
    
   
   b.UnlockBits(&bmData);
   b2->UnlockBits(&bmData2);   graphics.DrawImage(b2,0,0,iWidth,iHeight);
   graphics.DrawImage(&b, iWidth+10, 0, iWidth, iHeight);      }