1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
begin
BMPLoaded := false;
numFiles := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0) ;
if numFiles > 1 then
begin
ShowMessage('Vous ne pouvez déplacer un seul fichier image à la fois !') ;
end
else
begin
DragQueryFile(Msg.Drop, 0, @buffer, sizeof(buffer)) ;
try
Imagetest1.Picture.LoadFromFile(buffer) ;
except
on EInvalidGraphic do ShowMessage('Ce format n''est pas supporté !') ;
end;
end;
BMP := TBitmap.Create;
BMPLoaded := true;
try
Bmp.Width := imagetest1.Picture.Graphic.Width;
Bmp.Height := imagetest1.Picture.Graphic.Height;
Bmp.PixelFormat := pf24bit;
Bmp.Canvas.Draw(0,0,imagetest1.Picture.Graphic);
//BMP.Assign(image1.picture.Graphic);
if BMPLoaded then
begin
NewW := 640;
NewH := 480;
end;
{ enfin on vas injecter BMP dans le bitmap de Image1 (autosize = true) }
with Imagetest1.Picture.Bitmap do
begin
{ on definit les nouvelles dimensions }
width := NewW ;
height := NewH;
{ on travail en couleurs 24bpc }
pixelformat := pf24bit;
{ on sauvegarde l'ancien mode de redimension du canvas }
OldSBM := GetStretchBltMode(Canvas.Handle);
{ et on le definit en mode HALFTONE }
SetStretchBltMode(Canvas.Handle, HALFTONE);
{ on dessine l'image }
StretchBlt( Canvas.Handle, 0, 0, NewW, NewH,
BMP.Canvas.Handle, 0, 0, BMP.Width, BMP.Height,
SRCCOPY);
{ on restaure le mode de redimensionnement du canvas }
SetStretchBltMode(Canvas.Handle, OldSBM);
BMP.Assign(imagetest1.picture.bitmap);
imagetest1.Picture.Assign(bmp);
end;
finally
{ on libere BMP }
BMP.Free;
end;
{ on rafraichi Image1 }
Imagetest1.Refresh;
end; (*PanelImageDrop*) |
Partager