首页 > 其他 > 详细

TBitmapSurface.StretchFrom

时间:2017-01-03 18:31:53      阅读:166      评论:0      收藏:0      [点我收藏+]

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;

TBitmapSurface.StretchFrom

原文:http://www.cnblogs.com/h2zZhou/p/6245746.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!