如何用DELPHI区分彩色图和黑白图(多色与单色)??
如何用DELPHI区分彩色图和黑白图(多色与单色)??

解决方案 »

  1.   

    查一查整个图像上每一个像素的颜色的RGB分量不就行了吗?
    只要某个点的R,G,B分量不相等, 就是有彩色.
      

  2.   

    scanline。
    枚举象素,如果有一个象素是彩色的,那就退出。如果全是黑白2色,那就是单色了
      

  3.   

    临时写了个,还没试过。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;
      

  4.   

    多色,单色的区别只要在
    if (GetSLColor(p[x]) <> clBlack) and (GetSLColor(p[x]) <> clWhite) then
    做判断就可以了。
      

  5.   

    var
      Bitmap: TBitmap;
    begin
      Bitmap := TBitmap.Create;
      Bitmap.LoadFormFile('c:\1.bmp');
      if Bitmap.Monochrome then
        ShowMessage('黑白');
      Bitmap.Free;
    end;