本帖最后由 vbdotnet2001 于 2010-05-28 18:05:43 编辑

解决方案 »

  1.   

            /// <summary>
            /// 指针扫描bmp by skep99
            /// </summary>
            unsafe void dealbmp()
            {
                //lock
                GraphicsUnit unit = GraphicsUnit.Pixel;
                RectangleF boundsF = bitmap.GetBounds(ref unit);
                Rectangle bounds = new Rectangle((int)boundsF.X,
                    (int)boundsF.Y,
                    (int)boundsF.Width,
                    (int)boundsF.Height);            width = (int)boundsF.Width * sizeof(PixelData);
                if (width % 4 != 0)
                {
                    width = 4 * (width / 4 + 1);
                }            bitmapData =
                    bitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);            pBase = (Byte*)bitmapData.Scan0.ToPointer();            //处理
                Point size = PixelSize;            for (int x = 0; x < size.X; x++)
                {
                    for (int y = 0; y < size.Y; y++)
                    {
                        PixelData* pPixel = PixelAt(x, y);                    int value = (pPixel->red + pPixel->green + pPixel->blue) / 3;
                        pPixel->red = (byte)value;
                        pPixel->green = (byte)value;
                        pPixel->blue = (byte)value;
                    }
                }            //unlock
                bitmap.UnlockBits(bitmapData);
                bitmapData = null;
                pBase = null;
            }
      

  2.   

    using System.IO;
    using System.Drawing;
    Bitmap image = new Bitmap();
    MemoryStream ms = new MemoryStream();
    image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
    ms.ToArray();
      

  3.   

    GetPixel(j, i)直接获取对应像素的颜色值如果想操作指针的话
    不放用:
    unsafe
    {
    fixed *xxx = address;
    ...
    }
      

  4.   

    GetPixel方式极慢。
    能详细说明如何使用指针直接访问吗?
      

  5.   


    我的代码下面的语句需要在循环中遍历short数组,如下:
                    for (int y_value = 0; y_value < BitmapHeight; y_value++)
                    {
                        xyValue = y_value * bmp_width + x_value;
                        if (rgbValues[xyValue] == 0)
                        {
                            TempBuffer[j] |= OrBytes[i];
                            if ((TempBuffer[j] == 0xfd) || (TempBuffer[j] == 0xfe) || (TempBuffer[j] == 0xff))
                            {
                                TempBuffer[j + 1] = (byte)(TempBuffer[j] ^ 0x20);
                                TempBuffer[j] = 0xfd;
                                j++;
                            }
                        }
                        i++;
                        if (i == 8)
                        {
                            j++;
                            i = 0;
                        }
                    }最好能直接告诉我如何换成直接内存方式。不胜感激。
      

  6.   

    下面是我代码的后续部分,需要在循环中遍历short数组。if (rgbValues[xyValue] == 0)这句相当浪费时间。
                    for (int y_value = 0; y_value < BitmapHeight; y_value++)
                    {
                        xyValue = y_value * bmp_width + x_value;
                        if (rgbValues[xyValue] == 0)
                        {
                            TempBuffer[j] |= OrBytes[i];
                            if ((TempBuffer[j] == 0xfd) || (TempBuffer[j] == 0xfe) || (TempBuffer[j] == 0xff))
                            {
                                TempBuffer[j + 1] = (byte)(TempBuffer[j] ^ 0x20);
                                TempBuffer[j] = 0xfd;
                                j++;
                            }
                        }
                        i++;
                        if (i == 8)
                        {
                            j++;
                            i = 0;
                        }
                    }
      

  7.   

    http://topic.csdn.net/u/20100312/19/C8AD00FD-E3D2-42B5-9B39-AD55886346D5.htmlhttp://topic.csdn.net/u/20100503/12/4C9B6CAE-D56A-47D2-A864-C64E91323817.html
      

  8.   

    谢谢各位,发现用指针操作和Marshal.Copy到short[]遍历速度基本一样,好在节省了不少内存,感谢大家帮助。晚点结贴,看看各位还有没有更好的理解。