如何用DELPHI區分彩色圖和黑白圖(多色與單色)?? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiMultimedia/html/delphi_20061104175303177.html
如何用DELPHI區分彩色圖和黑白圖(多色與單色)??
如何用DELPHI區分彩色圖和黑白圖(多色與單色)??
急呀,幫忙呀
查一查整個映像上每一個像素的顏色的RGB分量不就行了嗎?
只要某個點的R,G,B分量不相等, 就是有彩色.
圖片資訊參看圖片格式
scanline。
枚舉象素,如果有一個象素是彩色的,那就退出。
如果全是黑白2色,那就是單色了
臨時寫了個,還沒試過。
function IsBlackAndWhiteGraphic(G: TGraphic): Boolean;
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array[0..32767] of TRGBTriple;
function GetSLColor(pRGB: TRGBTriple): TColor;
begin
Result := RGB(pRGB.rgbtRed, pRGB.rgbtGreen, pRGB.rgbtBlue);
end;
var
p: PRGBTripleArray;
x, y: Integer;
Bitmap: TBitmap;
begin
Result:= True;
Bitmap:= TBitmap.Create;
try
Bitmap.PixelFormat:= pf24bit;
Bitmap.Width:= G.Width;
Bitmap.Height:= G.Height;
Bitmap.Canvas.Draw(0,0,G);
for y := 0 to Bitmap.Height - 1 do
begin
p:= Bitmap.ScanLine[y];
for x := 0 to (Bitmap.Width - 1) do
begin
if (GetSLColor(p[x]) <> clBlack) and (GetSLColor(p[x]) <> clWhite) then
begin
Result:= False;
Break;
end;
end;
end;
finally
Bitmap.Free;
end;
end;
多色,單色的區別只要在
if (GetSLColor(p[x]) <> clBlack) and (GetSLColor(p[x]) <> clWhite) then
做判斷就可以了。
樓上的 看過 灰階圖麼。。
var
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
Bitmap.LoadFormFile('c:\1.bmp');
if Bitmap.Monochrome then
ShowMessage('黑白');
Bitmap.Free;
end;