将颜色值转变成int型 循环获取一张图片每个像素的颜色值

public static int ToArgb(this Color color) {
    int argb = color.A << 24;
    argb += color.R << 16;
    argb += color.G << 8;
    argb += color.B;
    return argb;
}

 

其实color自带了这个方法

 

 Bitmap image = (Bitmap)Bitmap.FromFile(@"c:/1.bmp");
            for (int x = 0; x < image.Width; x++)
            {
                for (int y = 0; y < image.Height; y++)
                {
                    System.Drawing.Color color = image.GetPixel(x, y);
                    int colorValue = color.ToArgb();
                }
            }

你可能感兴趣的:(c,image)