TBitmapSurface.StretchFrom

procedure TBitmapSurface.StretchFrom(const Source: TBitmapSurface; const NewWidth, NewHeight: Integer;
APixelFormat: TPixelFormat = TPixelFormat.None);
var
I, J: Integer;
SourceI, SourceJ: Single;
SourceIInt, SourceJInt: Integer;
SourceINext, SourceJNext: Integer;
SourceIOffset, SourceJOffset: Single;
D1, D2, D3, D4: Single;
P1, P2, P3, P4: TAlphaColorF;
Dest: TAlphaColorF;
begin
if APixelFormat = TPixelFormat.None then
APixelFormat := Source.PixelFormat;

SetSize(NewWidth, NewHeight, APixelFormat);

if (Source.Width > 1) and (Source.Width > 1) and (Width > 1) and (Width > 1) then
for I := Width - 1 downto 0 do
for J := 0 to Height - 1 do
begin
SourceI := (I / (Width - 1)) * (Source.Width - 1);
SourceJ := (J / (Height - 1)) * (Source.Height - 1);

SourceIInt := Trunc(SourceI);
SourceJInt := Trunc(SourceJ);
SourceINext := Min(Source.Width - 1, SourceIInt + 1);
SourceJNext := Min(Source.Height - 1, SourceJInt + 1);

SourceIOffset := Frac(SourceI);
SourceJOffset := Frac(SourceJ);

D1 := (1 - SourceIOffset) * (1 - SourceJOffset);
D2 := SourceIOffset * (1 - SourceJOffset);
D3 := SourceIOffset * SourceJOffset;
D4 := (1 - SourceIOffset) * SourceJOffset;

P1 := TAlphaColorF.Create(Source.Pixels[SourceIInt, SourceJInt]);
P2 := TAlphaColorF.Create(Source.Pixels[SourceINext, SourceJInt]);
P3 := TAlphaColorF.Create(Source.Pixels[SourceINext, SourceJNext]);
P4 := TAlphaColorF.Create(Source.Pixels[SourceIInt, SourceJNext]);

Dest := P1 * D1 + P2 * D2 + P3 * D3 + P4 * D4;
SetPixel(I, J, Dest.Clamp.ToAlphaColor);
end;
end;

上一篇:Flex显示麦克风当前音量


下一篇:JS获取IP、MAC和主机名的几种方法