Autor Beitrag
jsbach
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53

Win XP
D5 Ent
BeitragVerfasst: So 27.02.05 04:21 
Hallo, ich lasse ein Bild mit paintbox.canvas.pixel zeichnen. Nachdem ich ein neues Fenster geöffnet und wieder geschlossen habe, lasse ich das Bild einfach wieder mit onpaint neuzeichnen. Da es sich hier aber um echtzeit generierte Zoomausschnitte der Mandelbrotmenge handelt dauert das viel zu lange, vor allem bei großen Iterationswerten. Nun möchte ich, nachdem das Bild gezeichnet wurde, es in einer Bitmap speichern um es so schnell wieder aufzurufen. Wie mache ich das? Bitte genauen Code mitteilen. Kleines Beispiel oder so, da ich mit Bitmaps bisher noch nichts zu tun hatte.

Vielen Dank, jsbach
Lossy eX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1048
Erhaltene Danke: 4



BeitragVerfasst: So 27.02.05 20:20 
Als allererstes. Du solltest nur in sehr wenigen Fällen mit Canvas.Pixels arbeiten. Und zwar nur dann wenn du sehr wenig zeichnen musst. Da du aber einer komplettes Bild zeichnen willst solltest du darauf verzichten. Das Schnellste ist wenn du direkt auf den Speicher zugreifst.

Ich habe dir mal den komplleten Code angehangen. Alles wichtige steht als Kommentar drin. Hoffe es hilft. ;-)

ausblenden volle Höhe Delphi-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:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure PaintBox1Paint(Sender: TObject);
  private
    fBitmap : TBitmap;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  // Bild erstellen
  fBitmap := TBitmap.Create;

  // farbtiefe setzen
  fBitmap.PixelFormat := pf24Bit;

  // Größe setzen
  fBitmap.Width := PaintBox1.Width;
  fBitmap.Height := PaintBox1.Height;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  X, Y: Integer;
  pPix: PRGBTriple;
begin
  // Zeile für Zeile
  for Y := 0 to fBitmap.Height -1 do begin
    // Pointer auf Pixeldaten holen
    pPix := fBitmap.ScanLine[Y];

    // Spalte für Spalte
    for X := 0 to fBitmap.Width -1 do begin
      // Farbe setzen
      pPix^.rgbtRed   := 255;
      pPix^.rgbtGreen := 128;
      pPix^.rgbtBlue  := 0;

      // Ein Pixel weiter setzen
      Inc(pPix);
    end;
  end;

  // Paintbox neuzeichnen
  Paintbox1.Repaint;
end;


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  // Bild wieder frei geben
  fBitmap.Free;
end;


procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  // Bild auf Paintbox zeichnen
  PaintBox1.Canvas.Draw(0, 0, fBitmap);
end;


end.

_________________
Nur die Menschheit ist arrogant genug, um zu glauben sie sei die einzige intelligente Lebensform im All. Wo nicht mal das nachhaltig bewiesen wurde.
jsbach Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53

Win XP
D5 Ent
BeitragVerfasst: Di 01.03.05 00:51 
Vielen Dank erstmal, ich habe es jetzt wie folgt gemacht.
Erst in die Paintbox und dann sofort ins Bitmap zeichnen lassen.
Jedenfalls wollte ich es genau so haben.

ausblenden Delphi-Quelltext
1:
2:
paintbox.canvas.pixels[px,py]:=rgb(0,0,0);
bitmap.canvas.pixels[px,py]:=rgb(0,0,0);


MfG jsbach

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.

_________________
Was du für den Gipfel hälst, ist nur eine Stufe. (Seneca)