unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.ExtCtrls, StdCtrls, ExtDlgs, ImgList, commctrl;
type
TForm1 = class(TForm)
Image1: TImage;
MainMenu1: TMainMenu;
Fichier1: TMenuItem;
Ouvrir1: TMenuItem;
OpenDialog1: TOpenDialog;
OpenPicture: TOpenPictureDialog;
lblImageFileName: TLabel;
effacer1: TMenuItem;
procedure Ouvrir1Click(Sender: TObject);
procedure effacer1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
x, y : integer;
implementation
{$R *.dfm}
uses
Jpeg, FileCtrl;
//x:=image1.picture.width;
//y:=image1.picture.height;
//begin
//image1.canvas.pixels[x,j]:=image1.canvas.pixels[32,32] ;
procedure TForm1.effacer1Click(Sender: TObject);
begin
Image1.Picture := nil;
lblImageFileName.Caption :='';
end;
procedure TForm1.Ouvrir1Click(Sender: TObject);
var
ImgExt : string;
Jpeg: TJpegImage;
begin
if OpenPicture.Execute then
begin
//le traitement se fera d'après l'extension du fichier
ImgExt := LowerCase(ExtractFileExt(OpenPicture.FileName));
//Bitmap
if ImgExt = '.bmp' then
Image1.Picture.Bitmap.LoadFromFile(OpenPicture.FileName);
//Jpeg
if (ImgExt = '.jpg') or (ImgExt = '.jpeg') then
begin
Jpeg := TJpegImage.Create;
try
Jpeg.LoadFromFile(OpenPicture.FileName);
//copie de l'image du jpeg dans un bitmap
Image1.Picture.Bitmap.Assign(Jpeg);
finally
Jpeg.Free;
end;
end; {if (ImgExt = '.JPG') or (ImgExt = '.JPEG')}
//icones
if ImgExt = '.ico' then
Image1.Picture.Icon.LoadFromFile(OpenPicture.FileName);
//wmf et emf
if Pos(ImgExt, GraphicFileMask(TMetaFile)) <> 0 then
Image1.Picture.Metafile.LoadFromFile(OpenPicture.FileName);
//afficher le nom du fichier dans un espace restreint
lblImageFileName.Caption := MinimizeName(OpenPicture.FileName,
lblImageFileName.Canvas,
lblImageFileName.Width);
end; {if OpenPicture.Execute}
end;
end.
COMMENT ENRISTRER UNE ICONE APRES CHARGEMENT IMAGE