zoukankan      html  css  js  c++  java
  • bitmap的图像像素遍历方法

    public class FastBitmap
    {
        BitmapData bitmapData;
        public FastBitmap(Bitmap bitmap)
        {
            this.bitmapData=bitmap.LockBits(new Rectangle(0,0,bitmap.Width,bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bitmap.PixelFormat);
        }
        public unsafe Color GetPixel(int x,int y)
        {
            if (bitmapData.PixelFormat == PixelFormat.Format32bppRgb || bitmapData.PixelFormat == PixelFormat.Format32bppArgb)
            {
                byte* numPtr = (byte*)((int)bitmapData.Scan0 + y * bitmapData.Stride + x * 4);
                return Color.FromArgb(numPtr[3],numPtr[2], numPtr[1],numPtr[0]);
            }
            if (bitmapData.PixelFormat == PixelFormat.Format24bppRgb)
            {
                byte* numPtr2 = (byte*)((int)bitmapData.Scan0 + y * bitmapData.Stride + x * 3);
                return Color.FromArgb(numPtr2[2], numPtr2[1], numPtr2[0]);
            }
            return Color.Empty;
        }
    }
  • 相关阅读:
    PHP闭包的用法
    composer相关命令
    keepalievd
    docker-compose
    rabbitmq 知识点
    免费的mysql客户端管理工具
    git生成密钥
    rabbitmq在docker下进行cluster
    http状态码
    vmplayer固定IP
  • 原文地址:https://www.cnblogs.com/zhayunjia/p/5076048.html
Copyright © 2011-2022 走看看