如何用DELPHI區分彩色圖和黑白圖(多色與單色)??

來源:互聯網
上載者:User
如何用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;  
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.