我有一幅BMP图,它只有篮和白两种颜色的,我现在想把它变为红和白,有什么方法?
我想到了一种方法就是用循环整幅图,当颜色是篮的点,把它变为红,但我不想用这个方法,还有好的吗?我想用内置的函数

解决方案 »

  1.   

    改变图象的对比度、亮度、饱和度 
     宋体 // Bitmap.ScanLine[X] 可以获取图像象素的内存地址,24Bits的Bitmap的每一象// 素是以三原色RGB的次序存放的,改变RGB的值就可调节Bitmap的色彩.// R, G, B: -255~255procedure RGB(var Bmp: TBitmap; R, G, B: Integer);varX, Y: Integer;I: Byte;ColorTable: array[0..255] of TRGBColor;pRGB: PRGBColor;beginfor I := 0 to 255 dobeginColorTable[I].R := Byte(I + R);ColorTable[I].G := Byte(I + G);ColorTable[I].B := Byte(I + B);end;for Y := 0 to Bmp.Height - 1 dobeginpRGB := Bmp.ScanLine[Y];for X := 0 to Bmp.Width - 1 dobeginpRGB.R := ColorTable[pRGB.R].R;pRGB.G := ColorTable[pRGB.G].G;pRGB.B := ColorTable[pRGB.B].B;end;Inc(pRGB);end;end;// 改变图像的亮度,也只需调用RGB(Bmp, X, X, X)改变三原色.// 调节Bitmap的对比度// 应用公式: 新颜色值 = (旧颜色值 - 128) * 系数 + 128procedure Contrast(var Bmp: TBitmap; Amount: Integer);// Amount: -255~255varX, Y: Integer;I: Byte;ColorTable: array[0..255] of TRGBColor;pRGB: PRGBColor;beginfor I := 0 to 126 dobeginY := (Abs(128 - I) * Amount) div 256;ColorTable[I].r := GetRValue(Byte(I - Y));ColorTable[I].g := GetGValue(Byte(I - Y));ColorTable[I].b := GetBValue(Byte(I - Y));end;for I := 127 to 255 dobeginY := (Abs(128 - I) * Amount) div 256;ColorTable[I].r := GetRValue(Byte(I + Y));ColorTable[I].g := GetGValue(Byte(I + Y));ColorTable[I].b := GetBValue(Byte(I + Y));end;for Y := 0 to Bmp.Height - 1 dobeginpRGB := Bmp.ScanLine[Y];for X := 0 to Bmp.Width - 1 dobeginpRGB.R := ColorTable[pRGB.R].R;pRGB.G := ColorTable[pRGB.G].G;pRGB.B := ColorTable[pRGB.B].B;Inc(pRGB);end;end;end;// 改变饱和度procedure Saturation(var Bmp: TBitmap; Amount: Integer); // Amount: 0~510varGrays: array[0..767] of Integer;Alpha: array[0..255] of Word;Gray, X, Y: Integer;pRGB: PRGBColor;I: Byte;beginfor I := 0 to 255 do Alpha[I] := (I * Amount) shr 8;x := 0;for I := 0 to 255 dobeginGray := I - Alpha[I];Grays[X] := Gray; Inc(X);Grays[X] := Gray; Inc(X);Grays[X] := Gray; Inc(X);end;for Y := 0 to Bmp.Height - 1 dobeginpRGB := Bmp.ScanLine[Y];for X := 0 to Bmp.Width - 1 dobeginGray := Grays[pRGB.R + pRGB.G + pRGB.B];pRGB.R := Byte(Gray + Alpha[pRGB.R]);pRGB.G := Byte(Gray + Alpha[pRGB.G]);pRGB.B := Byte(Gray + Alpha[pRGB.B]);Inc(pRGB);end;end;end;
      

  2.   

    我就是不想用循环来取色,
    for Y := 0 to Bmp.Height - 1 dobeginpRGB := Bmp.ScanLine[Y];for X := 0 to Bmp.Width - 1 dobeginpRGB.R := ColorTable[pRGB.R].R;pRGB.G := ColorTable[pRGB.G].G;pRGB.B := ColorTable[pRGB.B].B;end;Inc(pRGB);end;end;用这个方法我会了,我想知有办法不用它也能把图中的所有的一只颜色变为另一种颜色