Recent Posts

Selamat datang di Coding Delphi Land Weblog kumpulan source code pemogram delphi

(Bukan maksud untuk menggurui tetapi marilah kita berbagi ilmu tuk perkembangan kemajuan teknologi kita

Senin, 16 November 2009

Open JPEG File in Delphi

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,jpeg, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button2: TButton;
Panel1: TPanel;
Image1: TImage;
procedure openjpeg;
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.openjpeg;
var
lJPG: TJPEGImage;
lI: integer;
lExt: string;
lStreamLoaded: boolean;
lStream: TmemoryStream;
begin
lExt := ExtractFileExt(OpenDialog1.Filename);
if length(lExt) > 0 then
for lI := 1 to length(lExt) do
lExt[lI] := upcase(lExt[lI]);
if ('.JPG'= lExt) or ('.JPG'= lExt) then begin
lStreamLoaded := true;
lStream := TMemoryStream.Create;
try
lStream.LoadFromFile(OpenDialog1.Filename);
lStream.Seek(0, soFromBeginning);
lJpg := TJPEGImage.Create;
try
lJpg.LoadFromStream(lStream);
lStream.Free;
lStreamLoaded := false;
Image1.Picture.Bitmap.PixelFormat := pf24bit;
Image1.Picture.Bitmap.Height := lJpg.Height;
Image1.Picture.Bitmap.Width := lJpg.Width;
Image1.Canvas.Draw(0,0,lJpg);
finally
lJPG.Free;
end;
finally
if lStreamLoaded then lStream.Free;
end; //try..finally
end;
Image1.Height := Image1.Picture.Height;
Image1.Width := Image1.Picture.Width;
Image1.refresh;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if not OpenDialog1.Execute then exit;
{OpenFile;}openjpeg;
end;

end.

0 komentar:

Posting Komentar