Autor Beitrag
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Mo 28.05.07 13:48 
Ich hab letztens eine PN von user profile iconheru bekommen, in der er mir seinen Code schickt, der nicht funktioniert. Hier mal der Code:
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:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
unit Moon2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm2 = class(TForm)
    bg: TImage;
    Label6: TLabel;
    Label7: TLabel;
    Image1: TImage;
    Image2: TImage;
    haus1: TImage;
    haus2: TImage;
    haus3: TImage;
    Wald: TImage;
    Teich: TImage;
    Baum: TImage;
    hhaus: TImage;
    silo: TImage;
    schild: TImage;
    hund: TImage;
    Label17: TLabel;
    Timer1: TTimer;
    Button1: TButton;
    procedure greyout(Bitmap: TBitmap; step, StepsCount: Integer; darkness: byte = 0);
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;
   x:integer;

implementation

{$R *.dfm}

procedure TForm2.greyout(Bitmap: TBitmap; step, StepsCount: Integer; darkness : byte = 0);
type
   pixel=Array[0..2] Of byte;
var
     p: ^pixel;
  x, y, temp: Integer;
  median, redstep, bluestep, greenstep: byte;
begin
  Bitmap.PixelFormat := pf24Bit;  
  if step > stepsCount then  
    step := StepsCount;  
  for y := 0 to Bitmap.Height - 1 do  
  Begin  
    p := Bitmap.ScanLine[y];  
    for x := 0 to Bitmap.Width - 1 do  
    begin  
      temp := ((p^[0] + p^[1] + p^[2]) Div 3) - darkness;  
      if temp < 0 then  
        temp := 0;  

 
      median := temp;  

 
      redstep := (median - p^[0]) Div StepsCount;
      bluestep := (median - p^[1]) Div StepsCount;  
      greenstep := (median - p^[2]) Div StepsCount;  

 
      p^[0] := p^[0] + redstep * step;  
      p^[1] := p^[1] + bluestep * step;  
      p^[2] := p^[2] + greenstep * step;

 
      inc(p);  
    end;  
  end;  
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
timer1.Enabled:=true;
end;

procedure TForm2.Timer1Timer(Sender: TObject);
begin
   haus1.Picture.Bitmap.LoadFromFile('system/bg_gruen_feld#.bmp');
   greyout(haus1.Picture.Bitmap, x, 30);
   inc(x);  
   if x > 30 then   
     Timer1.Enabled := false;
end; 

end.

Schaun wir mal, was daran "nicht funktioniert"...
Als erstes mal: Bitte beschreib nächstes mal genauer, was nicht funktioniert! Fehlermeldungen? Effekte die nicht so sein sollen? etc.
Dann fällt mir auf: Du lädst eine Datei aus dem Nirvana! Du kannst dir nie sicher sein, dass 'system/bg_gruen_feld#.bmp' auf eine Datei in deinem Programmordner verweist! Du musst unbedigt mit einer kompletten Pfadangabe arbeiten. Den Pfad deines Programmordners findest du mit ExtractFilePath(ParamStr(0))
ParamStr(0) liefert dabei den kompletten Pfad mit DeinProgramm.exe am Ende, ExtractFilePath gibt dann nur den Pfad zurück. (IIRC ist ein \ immer schon hinten dran)
So.. dann probier ich das mal kurz aus, was du da geschrieben hast.. sieht erstmal nicht falsch aus...
Klappt bei mir ganz gut, nur irgendwie scheint's mir nicht wirklich grau zu werden, sondern es bleiben ein paar Farben drin :gruebel:
Was mir bei ein paar Versuchen aufgefallen ist: Versuche mal StepsCount kleiner als 20 zu halten, wenn irgendwie möglich. Damit werden bessere Ergebnisse erzielt.
Ausserdem ist das Ganze noch nicht optimal, weil das Image.Picture.LoadFromFile wohl doch ein bisschen lang braucht wenn die Bilddatei sehr groß ist. Bei kleineren geht's auf die Art problemlos.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.