由Delphi中的图像灰度化代码看基本图像处理

[基础篇]

首先看一段实现24位色图像灰度化转换的代码

procedure   Grayscale(const   Bitmap:TBitmap);
var
    X:   Integer;
    Y:   Integer;
    R,G,B,Gray:   Byte;
    Color:   TColor;
begin
    for   Y   :=   0   to   (Bitmap.Height   -   1)   do
    begin
        for   X   :=   0   to   (Bitmap.Width   -   1)   do
        begin
            Color   :=   Bitmap.Canvas.Pixels[X,Y];
            R   :=   Color   and   $FF;
            G   :=   (Color   and   $FF00)   shr   8;
            B   :=   (Color   and   $FF0000)   shr   16;
            Gray   :=   Trunc(0.3   *   R   +   0.59   *   G   +   0.11   *   B);
            Bitmap.Canvas.Pixels[X,Y]   :=   Gray   shl   16   or   Gray   shl   8   or   Gray;
        end
    end
end;

{这段代码效率是非常低的,但可以方便我们理解同时一些问题}

Delphi的帮助中对TColor已经有了详细的描述,这可以方便我们理解上面的代码!

转自:http://topic.csdn.net/t/20030227/12/1472467.html //还有更详细的等着你看。

posted @ 2012-02-25 18:14  stma  阅读(1060)  评论(0)    收藏  举报