Autor Beitrag
pupu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 104

WinXP
Borland Delphi 7, Turbo Pascal 7
BeitragVerfasst: Fr 16.11.07 15:50 
Hi
In Info sollen wir nun in Delphi Bilder "manipulieren", d.h. farben ändern, kontrast verändern usw...
Hier is mein Code (hab dem eben etwas hingekleckst...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TDelFarbe.scanline();
  var
    x,n,m: Integer;
begin
  for m:=0 to Form1.Image1.Height-1 do begin
    x:=0;
    P:= Form1.Image1.picture.Bitmap.ScanLine[m];   //P--> PByteArray der Klasse TDelFarbe
    for n:=0 to Form1.Image1.Width-1 do begin
      r:=P[x];           //r,g,b--> Datentyp: Byte der Klasse TDelFarbe
      g:=P[x+1];
      b:=P[x+2];
      g:=0;
      P[x]:=r;
      P[x+1]:=g;
      P[x+2]:=b;
      x:=x+3;
      Application.ProcessMessages;
    end;
    Form1.ProgressBar1.position:=m;
  end;
end;


Mein Problem is, dass sich das Bild erst ändert, wenn man ein Fenster über das Image zieht und wieder wegbewegt...wie kann ich das ändern? und weite: wie kann ich in Laufzeit anzeigen wie sich die farben ändern?

Besten Dank im Voraus

_________________
Chuck Norris bekommt bei Praktiker auch auf Tiernahrung 20% oO


Zuletzt bearbeitet von pupu am Fr 16.11.07 16:13, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 16.11.07 15:57 
Moin!

Deine Code-Formatierung ist... naja... gewöhnungsbedürftig... :|

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:
procedure TDelFarbe.scanline();
  var
    x,n,m: Integer;
begin
  for m:=0 to Form1.Image1.Height-1 do begin
    x:=0;
    P:= Form1.Image1.picture.Bitmap.ScanLine[m];
    for n:=0 to Form1.Image1.Width-1 do begin
      r:=P[x];
      g:=P[x+1];
      b:=P[x+2];
      g:=0;
      P[x]:=r;
      P[x+1]:=g;
      P[x+2]:=b;
      x:=x+3;
      Form1.ProgressBar2.position:=n;
      Form1.Image1.Invalidate;
      Application.ProcessMessages;

    end;
    Form1.ProgressBar1.position:=m;
  end;
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
pupu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 104

WinXP
Borland Delphi 7, Turbo Pascal 7
BeitragVerfasst: Fr 16.11.07 16:16 
Danke für die schnelle antwort... das läuft jetzt.

Aber was bedeuten Zeile 18 und 19??? Bzw was erzielen die?

_________________
Chuck Norris bekommt bei Praktiker auch auf Tiernahrung 20% oO
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 16.11.07 16:17 
Moin!

Mit .Invalidate sagst du dem Control, dass es neu gezeichnet werden soll und APM führt es aus. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 17.11.07 15:17 
Invalidate markiert das Bild als "abgelaufen", sodass es bei der "nächsten Gelegenheit" neu gezeichnet wird. Die Kombination Invalidate/Application.ProcessMessages würde ich jetzt aber durch ein simples Repaint ersetzen, da das andere unnötig mehr Ressourcen (CPU) braucht. Application.ProcessMessages kannst du dann immer noch einmal pro Zeile ausführen, statt pro Pixel; oder ganz weglassen. Überhaupt würde ich kein Repaint pro Pixel machen...

Das Image würde ich noch opaque machen, um das Zeichnen des dahinterliegenden Controls zu verhindern (Image1.ControlStyle := Image1.ControlStyle + [csOpaque]) (weiterer Performancegewinn). Zu letzt gehst du im Code davon aus, dass das Pixelformat des geladenen Bitmaps pf24bit ist; falls nicht gibt's Exceptions oder ein falsches Ergebnis. Die Annahme kannst du beseitigen, in dem du am Anfang der Prozedur manuell das Pixelformat setzst (Image1.Picture.Bitmap.PixelFormat := pf24bit).

@Code Formatierung: Ist Geschmackssache aber das begin schreibt man üblicherweise auf einer separaten Zeile. Die andere Schreibweise sieht man eher bei Sprachen wie C. Mit Vorteil formatierst du den Code wie Borland. Dasselbe gilt auch für Konventionen für Variablennamen.
pupu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 104

WinXP
Borland Delphi 7, Turbo Pascal 7
BeitragVerfasst: Sa 17.11.07 15:30 
Besten Dank..
habs ma umgeändert und es geht um einiges schneller.
Das mit der Formatierung hab ich vor nem 3/4 Jahr auch noch anders gehalten... wie gesagt habs erstmal hingekleckst, aber nrmal raste ich auch immer wenn ich sone formatierung seh :-D

edit: was bewirkt opawue, bzw was bedeutet das? ixch muss das ja auch iwie erklären können wenn ichs in der schule weiterempfehl ;)

_________________
Chuck Norris bekommt bei Praktiker auch auf Tiernahrung 20% oO
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 17.11.07 15:34 
Mit Opaque wird in Repaint das darunterliegende Control nicht auch noch neu gezeichnet. Damit verhinderst du etwas Flackern und gewinnst an Geschwindigkeit.

Wenn du aber Wert auf Geschwindigkeit legst, dann solltest du das Zeichnen gleich selbst über BitBlt erledigen (dann musst du auch jeweils nicht das gesamte Image neu zeichnen sondern z.B. nur die geänderte Zeile). Aber vielleicht lässt du besser deine Finger davon, da das WinAPI ist und keine eigentliche Delphi-VCL-Funktionalität wie Repaint und co.