首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

将以下C#代码转换为DELPHI的··解决办法

2012-04-03 
将以下C#代码转换为DELPHI的C# codepublic Bitmap Convolute(Bitmap srcImage){if (scale 0) scale 1

将以下C#代码转换为DELPHI的··

C# code
public Bitmap Convolute(Bitmap srcImage)        {            if (scale == 0) scale = 1;            int width = srcImage.Width;            int height = srcImage.Height;            Bitmap dstImage = (Bitmap)srcImage.Clone();            BitmapData srcData = srcImage.LockBits(new Rectangle(0, 0, width, height),            ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);            BitmapData dstData = dstImage.LockBits(new Rectangle(0, 0, width, height),            ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);            int rectTop = 1;            int rectBottom = height - 1;            int rectLeft = 1;            int rectRight = width - 1;            unsafe            {                byte* src = (byte*)srcData.Scan0;                byte* dst = (byte*)dstData.Scan0;                int stride = srcData.Stride;                int offset = stride - width * BPP;                int pixel = 0;                src += stride;                dst += stride;                for (int y = rectTop; y < rectBottom; y++)                {                    src += BPP;                    dst += BPP;                    for (int x = rectLeft; x < rectRight; x++)                    {                      if (src[3] > 0)                     {                            for (int i = 0; i < 3; i++)                            {          pixel =src[i - stride - BPP] * topLeft +                 src[i - stride] * topMid +                  src[i - stride + BPP] * topRight +                  src[i - BPP] * midLeft +                                  src[i] * center +                                  src[i + BPP] * midRight +                                  src[i + stride - BPP] * bottomLeft +                                 src[i + stride] * bottomMid +                                  src[i + stride + BPP] * bottomRight;                                pixel = pixel / scale + kernelOffset;                                if (pixel < 0) pixel = 0;                                if (pixel > 255) pixel = 255;                                dst[i] = (byte)pixel;                            }                         }                        src += BPP;                        dst += BPP;                    }                     src += (offset + BPP);                    dst += (offset + BPP);                }            }            srcImage.UnlockBits(srcData);            dstImage.UnlockBits(dstData);            srcImage.Dispose();            return dstImage;        }


[解决办法]
你一下之间的结构是,应该知道了吧
[解决办法]
自己动手,丰衣足食~
[解决办法]
delphi的TBitmap,扫描行是TBitmap的ScanLine方法,得到的是字节数组的指针

热点排行