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
| procedure TForm1.Button2Click(Sender: TObject);
var w,h,ww,hh,i,j,k:integer;
pimg:tpngimage;
n:string;
srcrect,destrect:trect;
srcAlphaArray: pByteArray;
destAlphaArray: pByteArray;
x,y:integer;
begin
button2.hide;
ww:=img.width;
hh:=img.Height;
if (ww>0) and (hh>0) then
begin
w:=trunc(ww/spinedit1.Value);
h:=trunc(hh/spinedit2.Value);
{
ww : largeur de la grande image
hh : hauteur de la grande image
w : largeur des petites images
h : hauteurs des petites images
img : grande image
pimg: petite image
}
if not directoryexists('RESULTAT') then
createdir('RESULTAT');
k:=0;
n:= '/'+inttostr((trunc(ww/w))* (trunc(hh/h)));
for I := 0 to trunc(ww/w)-1 do
begin
for j := 0 to trunc(hh/h)-1 do
begin
try
inc(k);
pimg:=tpngimage.Create;
pimg.CreateBlank(img.Header.colortype,img.Header.bitdepth, w, h);
pimg.CreateAlpha;
// Remplissez le canal alpha de l'image de destination avec 0
pimg.Canvas.CopyMode := cmSrccopy;
// Spécifiez la région source et la région de destination
SrcRect := Rect(i * w, j * h, (i + 1) * w, (j + 1) * h);
DestRect := Rect(0, 0, w, h);
pimg.Canvas.copyrect(DestRect,img.canvas, SrcRect );
if img.TransparencyMode = ptmPartial then
begin
// Update destination png with tranparency data from original
for Y := 0 to h-1 do
begin
srcAlphaArray := img.AlphaScanline[Y+h*j];
destAlphaArray := pimg.AlphaScanline[Y];
for X := 0 to w-1 do
begin
destAlphaArray^[X] := srcAlphaArray^[X+w*i];
end;
end;
end;
pimg.SaveToFile('RESULTAT\'+inttostr(k)+'.png');
label5.Caption:=inttostr(k)+n;
application.processmessages;
finally
pimg.Free;
end;
end;
end;
showmessage('Terminé !');
end
else
showmessage('Erreur ! Image vide !');
button2.Show;
end; |
Partager