我这里有一个。
二次线性插值。没有处理四边,但是没有关系,
经我测试,放大后,显示效果很好。
function TForm1.MyInsertValue(lWidth, lHeight: integer;
pRGB: pRGBColor;
LineNum, ZoomScale: Single;
Bitmap: TBitmap): pRGBColor;
var
i1, i2, j1, j2, j, i: integer;
f1, f2, f3, f4, f12, f34, fNew: byte;
x, y: single;
pRGBTemp, pRGBNext: pRGBColor;
begin
//行数
x := (LineNum / ZoomScale);
i1 := trunc(x);
i2 := i1 + 1;
if i2>lWidth - 1 then
i2 := lWidth - 1;
Bitmap.PixelFormat := pf24Bit;
pRGBTemp := Bitmap.ScanLine[i1];
pRGBNext := Bitmap.ScanLine[i2];
//列数
for j := 0 to trunc(lWidth * ZoomScale) - 1do
begin
y := (j / ZoomScale);
j1 := trunc
;
j2 := j1 + 1;
if j2>lHeight - 1 then
j2 := lHeight - 1;
if (x=0) or (x=(lWidth*ZoomScale-1)/ZoomScale) or (y=0) or (y=(lWidth*ZoomScale-1)/ZoomScale) then
begin
pRGB[j].rgbtBlue := 0;
pRGB[j].rgbtGreen := 0;
pRGB[j].rgbtRed := 0;
end else
begin
{if (i1 = x) then
begin
if (j1 = y) then
begin
f1 := pRGBTemp^[j1].rgbtBlue;
fNew := f1;
end else
begin
f1 := pRGBTemp^[j1].rgbtBlue;
f2 := pRGBTemp^[j2].rgbtBlue;
fNew := trunc(f1 + (y - j1)*(f2 - f1));
end;
end else
begin
}
f1 := pRGBTemp^[j1].rgbtBlue;
f2 := pRGBTemp^[j2].rgbtBlue;
f3 := pRGBNext^[j1].rgbtBlue;
f4 := pRGBNext^[j2].rgbtBlue;
f12 := trunc(f1 + (y - j1)*(f2 - f1));
f34 := trunc(f3 + (y - j1)*(f4 - f3));
if f12 > 255 then
f12 := 255;
if f34 > 255 then
f34 := 255;
fNew := trunc(f12 + (x - i1) * (f34 - f12));
if fNew > 255 then
fNew := 255;
//end;
pRGB[j].rgbtBlue := fNew;
pRGB[j].rgbtGreen := fNew;
pRGB[j].rgbtRed := fNew;
end;
end;
MyInsertValue := pRGB;
end;