Autor Beitrag
Laluna
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win XP
Delphi 2006
BeitragVerfasst: Mo 23.04.07 15:16 
Hallo

wenn ich mein Bitmap mit folgendem Code in mein Image laden möchte, bildet das Programm immer nur eine weiße Fläche?
Das Bitamp ist aber 100% nicht komplett weiss.
Kann mir jemand einen Tipp geben, woran das liegen könnte?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Bitmapffnen1Click(Sender: TObject);
var
R : Trect;
begin
Result := TBitmap.Create;
Result.Free;
 with OpenDialog1 do
    if Execute then
      if FileExists(FileName) then
      begin
        Result.LoadFromFile(FileName);
        Image1.Picture.Bitmap.SetSize(Image1.Width, Image1.Height);
        R := rect(0,0, Image1.Width, Image1.Height);
        Image1.Picture.Bitmap.Canvas.StretchDraw(R, Result);
        Zoom := 100;
      end;
end;


Danke
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mo 23.04.07 15:19 
Ich würd mal eher sagen, es gibt ne EAccessViolation:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Bitmapffnen1Click(Sender: TObject);
var
R : Trect;
begin
Result := TBitmap.Create;
Result.Free;
 with OpenDialog1 do
    if Execute then
      if FileExists(FileName) then
      begin
        Result.LoadFromFile(FileName);
        Image1.Picture.Bitmap.SetSize(Image1.Width, Image1.Height);
        R := rect(0,0, Image1.Width, Image1.Height);
        Image1.Picture.Bitmap.Canvas.StretchDraw(R, Result);
        Zoom := 100;
      end;
end;

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Laluna Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win XP
Delphi 2006
BeitragVerfasst: Mo 23.04.07 15:29 
Super, danke jetzt funktioniert es.
Bin noch ziemlicher Anfänger...

aber muss ich das Bitmap nicht wieder freigeben? Ich wollte es nicht am Ende der Prozedur machen, da ich noch auf das "result" zugreifen muss und es daher nicht löschen wollte.
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mo 23.04.07 15:33 
Dann musst du es wohl außerhalbh der Prozedur freigeben...

Generell ist das aber nicht so toll, da dann die vorherige Instanz der Variable, der du result zuweist überschrieben wird und im Nirvana landet.
Besser iss das:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure MachWas(var bmp:Tbitmap);
begin
  bmp.TuDies;
  bmp.TuDas;
end;

procedure MachWasAnderes;
var
  bmp:TBitmap;
begin
  bmp:=TBitmap.Create;
  MachWas(bmp);
  bmp.TuNochWasAnderes;
  bmp.Free;
end;

Dadurch gehen dann keinerlei Instanzen verloren.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Laluna Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win XP
Delphi 2006
BeitragVerfasst: Mo 23.04.07 15:48 
Danke