Autor Beitrag
Green
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Fr 11.01.08 22:08 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.AssignColors(PB: TProgressbar);
var
  i, j: integer;
begin
  Image.canvas.brush.color:=clBlack;
  Image.canvas.rectangle(0,0,AufloesungX,AufloesungY);
  for i := 0 to AufloesungX - 1 do begin
    for j := 0 to AufloesungY - 1 do begin
      if not (CountArray[i,j] = Form3.TrackBar1.Position + 1) then
        Image.Canvas.Pixels[i,j] := Image10.Canvas.Pixels[1,CountArray[i,j]];
    end;
    PB.Position := PB.Position + 1;
  end;
  PB.Position := 0;
end;


Diese funktion wandelt ein aus zahlen bestehendes Zweidimensionales Array in ein Bild um.
Sie funktioniert ist aber recht langsam.

Bei einer aufloesung von 1280 * 1024 geht das durchaus 5-6 sekunden.

Programme wie Paint oder IrfanView (insbesondere) Irfan brauchen bruchteile von sekunden um ein Bild zu zeichnen und das ja auch aus gegebenen Zahlenwerten.

Wie kann man das jetzt optimieren??

lG Green
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Fr 11.01.08 22:20 
Ein erster Schritt gen Optimierung wäre wohl das Bild erstmal intern zu zeichnen, bevor Du es ausgibst/anzeigst.
Denn bei jedem Schritt, d.h. bei jedem gezeichneteten Pixel, muss deine Form neu gezeichnet werden und Das macht was aus.

Grüße
Marc
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Fr 11.01.08 23:02 
ausblenden 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:
procedure TForm1.AssignColors(PB: TProgressbar; NewPBBool: boolean = false; NewPB: TProgressBar = NIL);
var
  i, j, iy, ix: integer;
  lPixel: PRGBQuad;
  TempImage: TImage;
begin
  TempImage := TImage.Create(Self);
  TempImage.canvas.brush.color:=clBlack;
  TempImage.canvas.rectangle(0,0,AufloesungX,AufloesungY);
  TempImage.Picture.Bitmap.PixelFormat := pf32bit;
  TempImage.Canvas.MoveTo(0,0);
  for iy := 0 to AufloesungY - 1 do
  begin
    lPixel := TempImage.Picture.Bitmap.Scanline[iy];
    for  ix := 0 to AufloesungX - 1 do
    begin
      //if not (CountArray[ix,iy] = Form3.TrackBar1.Position + 1) then begin
        lPixel^.rgbRed := GetRValue(Image10.Canvas.Pixels[1,CountArray[ix,iy]]);
        lPixel^.rgbGreen := GetGValue(Image10.Canvas.Pixels[1,CountArray[ix,iy]]);
        lPixel^.rgbBlue := GetBValue(Image10.Canvas.Pixels[1,CountArray[ix,iy]]);
        lPixel^.rgbReserved := 0;
      //end;
      Inc(lPixel);
    end;
    PB.Position := PB.Position + 1;
  end;
  PB.Position := 0;
  Image.Canvas.Assign(TempImage.Canvas);
  if not Form2.Showing then PB.Visible := false;
end;


Eine kombination aus Scanline (schneller?) und dem was du gesagt hast, doch es endet mit einer exception welche auf Zeile 18 zeigt... was mach ich falsch?

//Edit Problem erledigt, hab vergessen width und height zu definieren. Allerdings kriege ich in dem moment wo das bild dann auf das Image zugewiesen werden soll folgende interessante Fehlermeldung:
"Can Not Assign a TBitmapCanvas To A TBitmapCanvas"
Konfus??
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 12.01.08 13:41 
Hey!
ausblenden Delphi-Quelltext
1:
2:
Image.Picture.Assign(TempImage.Picture);
TempImage.Free;


Gruß
Marc
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Sa 12.01.08 14:11 
Nutz am besten das TImage32 aus der Graphics32. Habe in einem meiner Projekte folgende Laufzeiten meines Programms gehabt:

TImage: 2:45:00h
TImage32: 0:03:30h

Die Komponenten der Graphics32 sind wirklich extrem schnell, was den Zugriff auf Pixel etc angeht...