static void Main()
{
Bitmap aa = file2img("test.jpg");
Bitmap cc = img_color_gradation(aa,100,0,0);
img2file(cc, "test1.jpg");
}
色阶调整代码
public static unsafe Bitmap img_color_gradation(Bitmap src, int r, int g, int b)
{
int width = src.Width;
int height = src.Height;
Bitmap back = new Bitmap(width, height);
Rectangle rect = new Rectangle(0, 0, width, height);
//这种速度最快
BitmapData bmpData = src.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);//24位rgb显示一个像素,即一个像素点3个字节,每个字节是BGR分量。Format32bppRgb是用4个字节表示一个像素
byte* ptr = (byte*)(bmpData.Scan0);
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
//ptr[2]为r值,ptr[1]为g值,ptr[0]为b值
int red = ptr[