Einzelnen Beitrag anzeigen

axelf98

Registriert seit: 27. Aug 2003
Ort: Ennepetal
440 Beiträge
 
Delphi 2005 Personal
 
#7

Re: Bildändern (StretchDraw, StretchBlt) nicht Thread-sicher

  Alt 3. Jul 2005, 18:12
Zitat von SirThornberry:
@axelf98: Wie hast du das ganze umgesetzt? Arbeitest du mit der Delphiklasse TThread?
Ja genau, meine Record:

Delphi-Quellcode:
Type TFoto = record // Was alles drin sein kann
 FileScr: String;
 Vorschau: TBitmap;
end;
Type pTFoto = ^TFoto; // Pointer für den Record
Mein Thread:
Delphi-Quellcode:
type
  Vorschaubildererstellen = class(TThread)

  public
    constructor INIT(Daten: TFotoShow; Gaug: TGauge; Gri: TStringgrid; Pane: TPanel);
  private
    { Private-Deklarationen }
    mFotos: TFotoShow; // Für den Daten Zugriff aufs Form Übergabe der Pointer
    Gauge: TGauge;
    Grid: TStringgrid;
    Panel: TPanel;
  protected
    procedure Vorschauerstelleneinzeln(Nr,Gr: integer; Fot: pTFoto);
    procedure Execute; override;
  end;

implementation
uses main;

constructor Vorschaubildererstellen.INIT(Daten: TFotoShow; Gaug: TGauge; Gri: TStringgrid; Pane: TPanel);
begin
 mFotos := Daten;
 Gauge := Gaug;
 Grid := Gri;
 Panel := Pane;
 inherited create(false);
end;

procedure Vorschaubildererstellen.Execute; // Thread
var i: integer;
  tmp : pTFoto;
begin

 for i := 0 to mFotos.AnzahlFotos-1 do
 begin
  tmp := mFotos.Elemente.Items[i];
  if tmp^.Vorschau = nil then
  begin
  Vorschauerstelleneinzeln(i,mFotos.VorschauGr,tmp);
  end;
 end;
end;

procedure Vorschaubildererstellen.Vorschauerstelleneinzeln(Nr,Gr: integer; Fot: pTFoto);
var LadImage: Timage;
    Verh: Double;
    hoehe, weite,x: integer;
    Extention: String;
    LadBitmap: TBitmap;
    jpg: TJPEGImage;
    MegaP: Real;
    Verk: TBildverkleiner;
begin

 try
 Extention := Ansilowercase(Extractfileext(Fot^.FileScr));

  if Fot^.Vorschau = nil then
  Fot^.Vorschau := TBitmap.Create;

 if (Extention = '.jpg') OR (Extention = '.jpeg') then
 begin /// JPGS schnell!!!! ---------------------------------
  LadBitmap := TBitmap.Create;
  jpg := TJPEGImage.create;
  jpg.LoadFromFile(Fot^.FileScr);

   MegaP := (JPG.Width*JPG.Height)/1000000;
   if MegaP > 1 then
    JPG.Scale := jsEighth ELSE // schnell!!
   if MegaP > 0.3 then
    JPG.Scale := jshalf ELSE
    JPG.Scale := jsFullSize;

  LadBitmap.Assign(jpg);

 if (LadBitmap.Width > 0) AND (LadBitmap.Height > 0)then
  begin
   Verh := LadBitmap.Width/LadBitmap.Height;
   Fot^.Vorschau.Width := Gr;
    Fot^.Vorschau.Height := Gr;
   if Verh >= 1 then
   begin
   hoehe := Round(Gr/Verh);
   x := round((Gr-hoehe)/2);
  Fot^.Vorschau.Canvas.StretchDraw(Rect(0,x,Gr,hoehe+x),LadBitmap); // HIER wird gemalt
   end ELSE
   begin
   weite := Round(Gr*Verh);
   x := round((Gr-weite)/2);
   Fot^.Vorschau.Canvas.StretchDraw(Rect(x,0,weite+x,gr),LadBitmap); // HIER wird gemalt
   end;
   end;
  jpg.Free;
  LadBitmap.Free;
 end ELSE
 begin

 /// BMPS oder anderes
  
  end ELSE
  begin
   Fot^.Vorschau := nil;
  end;
  LadImage.Free;
 end;
 except
    Fot^.Vorschau := nil;
  end;
 end;
Ich schreibe nochmals, dass jede andere Prozedur, sei es Canvas.Draw(..), Canvas.Rectangle oder ähnliches anstelle des StretchDraw wunderbar funktioniert und jedes Mal gezeichnet wird!
  Mit Zitat antworten Zitat