// Es werden monochrome Strichbilder erstellt.
// Wozu das gut ist, weiß der Teufel.


// Getestet mit RS 10.4 unter
Win11


Bild

unit Unit1; 
 
interface 
 
uses 
  Winapi.Windows, System.SysUtils, System.Classes, Vcl.Graphics, 
  Vcl.Controls, Vcl.Forms, Vcl.StdCtrls, Vcl.ExtCtrls; 
 
type 
  TForm1 = class(TForm) 
    Image1: TImage; 
    Image2: TImage; 
    Button1: TButton; 
    procedure FormCreate(Sender: TObject); 
    procedure FormDestroy(Sender: TObject); 
    procedure Button1Click(Sender: TObject); 
  private 
    { Private-Deklarationen } 
  public 
    { Public-Deklarationen } 
    procedure Wandeln(gr: TGraphic); 
    procedure Bearbeiten; 
  end; 
 
var 
  Form1: TForm1; 
 
implementation 
 
{$R *.dfm} 
 
uses Vcl.Imaging.jpeg; // Falls man ein JPG lädt 
 
var 
  Jpg: TJpegImage; 
  bmp: TBitmap; 
  P2, Pb: PByteArray; 
  r, g, b: Byte; 
  Stift: TColor = clMaroon; // z.B. 
  Papier: TColor = $E8FFFF; // z.B. 
  f: Integer = 4; 
  faktor: Integer = 2; // normal = 1 
  schwelle: Integer = 1375; 
 
procedure TForm1.Bearbeiten; 
var 
  i: Integer; 
  procedure PX(x: Integer); 
  var 
    gs, y, d: Integer; 
    procedure links; 
    begin 
      Pb[x - 3] := b; 
      Pb[x - 2] := g; 
      Pb[x - 1] := r; 
    end; 
    procedure rechts; 
    begin 
      Pb[x + 3] := b; 
      Pb[x + 4] := g; 
      Pb[x + 5] := r; 
    end; 
 
  begin 
    y := 0; 
    while y < bmp.height do 
    begin 
      d := -3; 
      gs := 0; 
      P2 := Image2.Picture.Bitmap.ScanLine[y]; 
      while d < 9 do 
      begin 
        gs := gs + P2[x + d] + P2[x + d + 1] + P2[x + d + 2]; 
        inc(d, 3); 
      end; 
      Pb := bmp.ScanLine[y]; 
      if gs < schwelle then 
      begin 
        rechts; 
        links; 
      end; 
      inc(y); 
    end; 
  end; 
 
begin 
  i := 1; 
  with bmp.Canvas do 
  begin 
    Brush.Color := Papier; 
    Fillrect(Cliprect); 
    Pen.Color := Stift; 
    while i < bmp.width do 
    begin 
      PX(i * 3); 
      MoveTo(i, 0); 
      LineTo(i, height); 
      inc(i, f); 
    end; 
  end; 
  with Image2.Picture.Bitmap do 
  begin 
    setsize(bmp.width * faktor, bmp.height * faktor); 
    Canvas.StretchDraw(rect(0, 0, width, height), bmp); 
  end; 
end; 
 
procedure TForm1.Wandeln(gr: TGraphic); 
begin 
  r := GetRValue(Stift); 
  b := GetBValue(Stift); 
  g := GetGValue(Stift); 
  with Image1.Picture.Bitmap do // Anzeige Original 
  begin 
    width := gr.width; 
    height := gr.height; 
    Canvas.Draw(0, 0, gr); 
  end; 
  with bmp do 
  begin 
    PixelFormat := pf24Bit; 
    width := ((gr.width div f) + ord(frac(gr.width / f) > 0)) * f; 
    height := gr.height; 
  end; 
  with Image2.Picture.Bitmap do 
  begin 
    PixelFormat := pf24Bit; 
    width := bmp.width; 
    height := bmp.height; 
    Canvas.StretchDraw(rect(0, 0, width, height), gr); 
  end; 
end; 
 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
  Jpg.LoadFromFile('D:\Bilder\det.jpg'); 
  Wandeln(Jpg); 
  Bearbeiten; 
end; 
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
  Jpg := TJpegImage.Create; 
  bmp := TBitmap.Create; 
  Image1.Autosize := true; 
  Image2.Autosize := true; 
end; 
 
procedure TForm1.FormDestroy(Sender: TObject); 
begin 
  FreeAndNil(bmp); 
  FreeAndNil(Jpg); 
end; 
 
end.
  
		
		
		
		

Zugriffe seit 6.9.2001 auf Delphi-Ecke