Pisałem program konwertujący bitmapy na JPEG lub odwrotnie. Tak wygląda:
Jednak po wczytaniu obrazu, wybraniu typu konwersji i kliknięciu przycisku Konwertuj pokazuje się taki błąd:
Nie mam pojęcia gdzie zrobiłem błąd. Proszę o pomoc. To kod programu:
unit Unit9;
interface
uses
Windows, Messages, JPEG, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ExtDlgs;
type
TForm2 = class(TForm)
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
SavePictureDialog1: TSavePictureDialog;
Button2: TButton;
Button1: TButton;
Label1: TLabel;
RadioGroup1: TRadioGroup;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
Bitmap: TBitmap;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
if openpicturedialog1.execute
then image1.picture.loadfromfile(openpicturedialog1.filename);
Button2.Enabled:= True;
end;
procedure TForm2.Button2Click(Sender: TObject);
var
JPEGImage: TJPEGImage;
Bitmap: TBitmap;
begin
case RadioGroup1.ItemIndex of
0:
try
JPEGImage:=TJPEGImage.Create;
JPEGImage.CompressionQuality:=80;
JPEGImage.Assign(Bitmap);
if SavePictureDialog1.Execute then
JPEGImage.SaveToFile(SavePictureDialog1.FileName);
Label1.Caption:='Done!';
finally
Bitmap.Free;
JPEGImage.Free;
end;
1:
try
Bitmap:=TBitmap.Create;
with Bitmap do
begin
PixelFormat:=pf24bit;
Height:=JPEGImage.Height;
Width:=JPEGImage.Width;
Canvas.Draw(0,0, JPEGImage);
end;
if SavePictureDialog1.Execute then
Bitmap.SaveToFile(SavePictureDialog1.FileName);
finally
Bitmap.Free;
JPEGImage.Free;
end;
end;
end;
end.