English 中文(简体)
使用点时使用过多的记忆?
原标题:excessive memory usage when using pointers?

我的职能是绘制一张彩色的比照图,使其处于灰色,但记忆的使用太高。 我使用了沼泽地。 以前使用的制版方法不出现传闻,但速度较慢。 任何帮助?

        Bitmap b = a.Clone(new Rectangle(0, 0, a.Width, a.Height), a.PixelFormat);
        BitmapData bData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, b.PixelFormat);
        byte bitsPerPixel = Convert.ToByte(Image.GetPixelFormatSize(bData.PixelFormat));

        /*This time we convert the IntPtr to a ptr*/
        byte* scan0 = (byte*)bData.Scan0.ToPointer();

        //Console.WriteLine(scan0);
        for (int i = 0; i < bData.Height; ++i)
        {
            for (int j = 0; j < bData.Width; ++j)
            {
                byte* data = scan0 + i * bData.Stride + j * bitsPerPixel / 8;

                data[0] = data[1] = data[2] = (byte)((data[0] + data[1] + data[2]) / 3);

            }
        }
        b.UnlockBits(bData);
        bData = null;
        return b;
问题回答

I don t know about the memory leak but there is a better way to convert image to greyscale. Visit this page, you ll find three ways to do it, with third way called "Short and Sweet" being the fastest. And sweetest.

甚至在谷歌和互联网档案反馈机器上也找不到外部网站,但短程和轮式法则在另一个SO 回答





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签