• 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;

  • 相关阅读:
    第十一周课程总结
    第十周课程总结
    第九周课程总结&实验报告(七)
    第八周课程总结&实验报告六
    第七周
    第六周
    课程总结
    第十四周课程总结&实验报告
    第十三周总结
    第十二周总结
  • 原文地址:https://www.cnblogs.com/h2zZhou/p/6245746.html
Copyright © 2020-2023  润新知