Hvala ti Bancika, uspjela sam se snaci! :)
Evo, primjera koji konvertuje sliku .jpg u .bmp, ispisuje na odredjenom mjestu 'Hello!', a zatim tu sliku konvertuje ponovo u .jpg, bez većih gubitaka na kvaliteti slike.
***********************************************************
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, JPEG, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
Image1: TImage;
SaveDialog1: TSaveDialog;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Bitmap: TBitmap;
implementation
{$R *.dfm}
Function Jpeg2Bitmap(JPEGFile : String) : TBitmap; //osim konverzije, ovdje se vrsi
//i ispis teksta na konvertovani
//.bmp file
var
oJPEG : TJPEGImage;
objLogFont: TLogFont;
fntSaveFont: TFont;
begin
oJPEG := TJPEGImage.Create ;
oJPEG.LoadFromFile(JPEGFile);
Result := TBitmap.Create;
Result.Assign(oJPEG);
fntSaveFont := TFont.Create;
Form1.Label1.Caption:='Hello!';
fntSaveFont.Assign(result.Canvas.Font);
with result.Canvas do begin
Font.Handle := CreateFontIndirect(objLogFont);
SetBkMode(Handle, TRANSPARENT);
Font.Assign(fntSaveFont);
Font.Size:=35;
Font.Name:='Arial';
Font.Color:=clGreen;
end;
result.Canvas.TextOut(10,240,Form1.Label1.Caption);
fntSaveFont.Free;
oJPEG.Free;
end;
procedure TForm1.FormCreate(Sender: TObject); //tokom kreiranja forme, ucitava se
//.jpg slika iz odredjenog direktorija
//te se pozivom fje Jpeg2Bitmap
//konvertuje u .bmp
var
oJPEG : tBitmap;
oBitmap: TBitmap;
begin
oJPEG := tBitmap.Create;
//Call the function to get the JPEG object.
oJPEG :=Jpeg2Bitmap('D:\LampOn.jpg');
//Now you can save it to a file or do something else with it.
oJPEG.SaveToFile('d:\LampOff.bmp');
oJPEG.Free;
end;
procedure TForm1.Button1Click(Sender: TObject); //ovim ucitavamo .bmp fajl
begin
if OpenDialog1.Execute then
begin
Bitmap:=TBitmap.Create;
Bitmap.LoadFromFile(OpenDialog1.FileName);
Image1.Picture.LoadFromFile(OpenDialog1.FileName);
end;
end;
procedure TForm1.Button2Click(Sender: TObject); //konvertuje se .bmp u .jpg
var
JPEGImage: TJPEGImage;
begin
try
JPEGImage:=TJPEGImage.Create;
JPEGImage.CompressionQuality:=80;
JPEGImage.Assign(Bitmap);
if SaveDialog1.Execute then
JPEGImage.SaveToFile(SaveDialog1.FileName);
Label1.Caption:='Konverzija izvrsena!';
finally
Bitmap.Free;
JPEGImage.Free;
end;
end;
end.
Carpe diem!