zoukankan      html  css  js  c++  java
  • C# 指针操作图像

        Bitmap bmp01;

                int BmpWidth = bmp01.Width;
                int BmpHeight = bmp01.Height;
                PixelFormat BmpPixelFormat = bmp01.PixelFormat;

                byte* RBuff = (byte*)Marshal.AllocHGlobal(177600);
                byte* GBuff = (byte*)Marshal.AllocHGlobal(177600);
                byte* BBuff = (byte*)Marshal.AllocHGlobal(177600);

                BitmapData bmpData = bmp01.LockBits(new Rectangle(0, 0, BmpWidth, BmpHeight), ImageLockMode.WriteOnly, BmpPixelFormat);
                int stride = bmpData.Stride;  // 扫描线的宽度
                int offset = stride - BmpWidth*3;  // 显示宽度与扫描线宽度的间隙
                byte* pSrc = (byte*)bmpData.Scan0;  // 获取bmpData的内存起始位置

                int posScan = 0, posReal = 0;   // 分别设置两个位置指针,指向源数组和目标数组
                for (int x = 0; x < BmpHeight; x++)
                {
                    //// 下面的循环节是模拟行扫描
                    for (int y = 0; y < BmpWidth; y++)
                    {
                        RBuff[posScan] = pSrc[posReal];
                        GBuff[posScan] = pSrc[posReal+1];
                        BBuff[posScan] = pSrc[posReal+2];

                        posScan++;
                        posReal += 3;
                    }
                    posReal += offset;  //行扫描结束,要将目标位置指针移过那段“间隙”
                }
                 bmp01.UnlockBits(bmpData);

  • 相关阅读:
    学习PetShop3.0(9)工厂的资料
    net程序架构开发
    《解剖PetShop》系列之一
    与数据库相关的名词解释
    asp 导出Excel
    《解剖PetShop》系列之二
    业务模块的设计原则
    《解剖PetShop》系列之三
    JAVA之BigInteger(转)【转】【很好用啊】
    php_mcrypt.dll无法加载解决方法
  • 原文地址:https://www.cnblogs.com/QuincyYi/p/12717849.html
Copyright © 2011-2022 走看看