Thema: Delphi Bilder verkleinern

Einzelnen Beitrag anzeigen

Benutzerbild von Mavarik
Mavarik

Registriert seit: 9. Feb 2006
Ort: Stolberg (Rhld)
4.144 Beiträge
 
Delphi 10.3 Rio
 
#3

Re: Bilder verkleinern

  Alt 12. Jul 2006, 09:45
So zum Beispiel:


Delphi-Quellcode:
  Procedure GetDimentions(Xmax,Ymax:integer;Bildname:string;Var Dimx,Dimy:integer;Oversize:boolean);
  var
    x,y,Xa,Ya : integer;
    Image1 : TImage;
  begin
      try
      x := 0;
      y := 0;
      Image1 := TImage.Create(nil);
      Image1.AutoSize := true;
      Image1.Picture.LoadFromFile(Bildname);
      x := Image1.width;
      y := Image1.height;
      finally
        Image1.Free;
      end;

      try

        if (X < XMax) and (Y < YMax)
          then begin // Grafik zu klein!
                  if Oversize then
                        begin
                          if Abs(Y / Ymax) < Abs(X / Xmax)
                            then begin // X Maximieren
                                   DimX := XMax;
                                   DimY := Y*XMax div X;
                                 end
                            else begin // Y Maximieren
                                   DimY := YMax;
                                   DimX := X*YMax div Y;
                                 end;
                        end
                   else begin
                          Dimx := X;
                          DimY := Y;
                        end;
               end
          else begin // Grafik größer!
                  if (X < XMax) or (Y < YMax)
                    then begin
                           if Y>=Ymax
                             then begin // Y Maximieren
                                    DimY := YMax;
                                    DimX := X*YMax div Y;
                                  end
                             else begin // X Maximieren
                                    DimX := XMax;
                                    DimY := Y*XMax div X;
                                  end
                         end
                    else begin
                           if Abs(Y / Ymax) > Abs(X / Xmax)
                             then begin // Y Maximieren
                                    DimY := YMax;
                                    DimX := X*YMax div Y;
                                  end
                             else begin // X Maximieren
                                    DimX := XMax;
                                    DimY := (Y*XMax) div X;
                                  end
                        end;
               end;

      except
        DIMX := 0;
        DIMY := 0;
      end;
  end;
Grüsse Frank
  Mit Zitat antworten Zitat