delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
如何用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;  
 

posted on 2008-11-05 09:37 delphi2007 阅读(728) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。