Einzelnen Beitrag anzeigen

Benutzerbild von Olli73
Olli73

Registriert seit: 25. Apr 2008
Ort: Neunkirchen
666 Beiträge
 
#16

AW: Bilder speichern

  Alt 13. Okt 2014, 18:29
PS: Bitmap.SaveToFile(... + 'myfile.jpg'); speichert zwar das Bild in einer Datei, aber auch wenn die Datei *.jpg heißt, ist darin natürlich ein Bitmap (*.bmp), da Bitmap halt ein Bitmap ist und auch nur Bitmaps speichern kann.
Zumindest Firemonkey/XE5 ist intelligenter als man denkt:

Delphi-Quellcode:
procedure TBitmap.SaveToFile(const AFileName: string; const SaveParams: PBitmapCodecSaveParams = nil);
begin
  TBitmapCodecManager.SaveToFile(AFileName, Self, SaveParams);
end;


class function TBitmapCodecManager.SaveToFile(const AFileName: string; const Bitmap: TBitmap;
  const SaveParams: PBitmapCodecSaveParams = nil): Boolean;
var
  Codec: TCustomBitmapCodec;
  Descriptor: TBitmapCodecClassDescriptor;
begin
  Result := False;
  if Assigned(FBitmapCodecClassDescriptors) then
    for Descriptor in FBitmapCodecClassDescriptors do
      if SameText(ExtractFileExt(AFileName), Descriptor.Extension, loUserLocale) and Descriptor.CanSave then
      begin
        Codec := Descriptor.BitmapCodecClass.Create;
        try
          Result := Codec.SaveToFile(AFileName, Bitmap, SaveParams);
        finally
          Codec.Free;
        end;
      end;
end;
Ich war auch (vor einiger Zeit) erstaunt, dass das so einfach geht.

Gruß,
Olli

Edit: Ich war zu lahm...

Geändert von Olli73 (13. Okt 2014 um 18:32 Uhr) Grund: Edit: Ich war zu lahm...
  Mit Zitat antworten Zitat