unit filmbars;
interface
uses
Graphics, JPeg, Sysutils;
type
TFilmBarCreater =
class(TObject)
private
FImage: TJPegImage;
FBitmap: TBitmap;
FColor: TColor;
procedure AdjustImageSize(AWidth, AHeight: Integer);
public
constructor Create(
const ASrcFilename, ADestFilename:
String; AWidth,
AHeight: Integer; ABarColor: TColor);
end;
implementation
{ TFilmBarCreater }
procedure TFilmBarCreater.AdjustImageSize(AWidth, AHeight: Integer);
var
temp: TBitmap;
widthDiff, heightDiff: Integer;
begin
//Kopie anlegen
temp := TBitmap.Create;
temp.Assign(FBitmap);
//Größendifferenz des neuen Bildes zum alten bestimmen
widthDiff := AWidth - FBitmap.Width;
heightDiff := AHeight - FBitmap.Height;
//Original in der Größe ändern
FBitmap.Width := AWidth;
FBitmap.Height := AHeight;
//Original mit Streifenfarbe füllen und Kopie einzeichnen
FBitmap.Canvas.Brush.Color := FColor;
FBitmap.Canvas.FillRect(FBitmap.Canvas.ClipRect);
FBitmap.Canvas.Draw(widthDiff
div 2, heightDiff
div 2, temp);
temp.Free;
end;
constructor TFilmBarCreater.Create(
const ASrcFilename, ADestFilename:
String;
AWidth, AHeight: Integer; ABarColor: TColor);
var
CompressionQuality: TJPEGQualityRange;
begin
FImage := TJPegImage.Create;
FBitmap := TBitmap.Create;
FColor := ABarColor;
FImage.LoadFromFile(ASrcFilename);
//JPEG-Qualitätsdaten zwischenspeichern
CompressionQuality := FImage.CompressionQuality;
//JPEG in Bitmap kopieren
FBitmap.Assign(FImage);
//Bitmap in richtige Größe bringen
AdjustImageSize(AWidth, AHeight);
//Bitmap wieder in JPEG umwandeln
FImage.Assign(FBitmap);
//JPEG-Qualitätsdaten wiederherstellen
FImage.CompressionQuality := CompressionQuality;
FImage.Compress;
//JPEG speichern
FImage.SaveToFile(ADestFilename);
FImage.Free;
FBitmap.Free;
end;
end.