Entwickler-Ecke

Multimedia / Grafik - Bitmap in SW


Anonymous - Mo 10.03.03 23:55
Titel: Bitmap in SW
Hi
Wie kann ich ein Bitmap das Farbig ist Schwarz/Weiß machen?


Popov - Di 11.03.03 00:40

Ich weiß nicht was du mit schwarzweiß meinst. Eine einfache Methode ist über TBitmap.Mask. Aber hier hast du wirklich nur SW. Ober meinst du Grautöne?


Anonymous - Di 11.03.03 16:33

Grautöne meinte ich.


Tomac - Di 11.03.03 18:18

Schau mal hier:

http://home.pages.at/dbr-software/delphi/grau.htm

mfG


toms - Di 11.03.03 18:31


Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
procedure ConvertBitmapToGrayscale(const Bitmap: TBitmap);
type
  PPixelRec = ^TPixelRec;
  TPixelRec = packed record
    B: Byte;
    G: Byte;
    R: Byte;
    Reserved: Byte;
  end;
var
  X: Integer;
  Y: Integer;
  P: PPixelRec;
  Gray: Byte;
begin
  Assert(Bitmap.PixelFormat = pf32Bit);
  for Y := 0 to (Bitmap.Height - 1) do
  begin
    P := Bitmap.ScanLine[Y];
    for X := 0 to (Bitmap.Width - 1) do
    begin
      Gray := Round(0.30 * P.R + 0.59 * P.G + 0.11 * P.B);
      // Gray := (P.R shr 2) + (P.R shr 4) + (P.G shr 1) + (P.G shr 4) + (P.B shr 3);
      P.R := Gray;
      P.G := Gray;
      P.B := Gray;
      Inc(P);
    end;
  end;
end;


Anonymous - Di 11.03.03 22:28

THX. Es klappt alles.