Try a better interpolation:
[code]Private Function BilinearInterpolation(OriginalPicture as Picture, newWidth as Integer, newHeight as Integer, constrainProportion as Boolean) as Picture
dim w as Integer = OriginalPicture.Width
dim h as Integer = OriginalPicture.Height
dim x_ratio as Double = (w - 1)/newWidth
dim y_ratio as Double = (h - 1)/newHeight
if constrainProportion then
if x_ratio >= y_ratio then
newHeight = h/x_ratio
else
newWidth = w/y_ratio
end if
x_ratio = max(x_ratio, y_ratio)
y_ratio = max(x_ratio, y_ratio)
end if
dim oldSurf as RGBSurface = OriginalPicture.RGBSurface
dim oldMask as Picture = OriginalPicture.CopyMask
dim oldMaskSurf as RGBSurface
if oldMask <> nil then oldMaskSurf = OriginalPicture.CopyMask.RGBSurface
dim InterpolatedPicture as new Picture(newWidth, newHeight, 32)
dim InterpolatedSurf as RGBSurface = InterpolatedPicture.RGBSurface
dim InterpolatedMaskSurf as RGBSurface = InterpolatedPicture.mask.RGBSurface
dim x, y, alphaValue as Integer
dim x_diff, y_diff, blue, red, green, gray as Double
dim a, b, c, d as Color
for i as Integer = 0 to (newHeight - 1)
for j as Integer = 0 to (newWidth - 1)
x = x_ratio * j
y = y_ratio * i
x_diff = (x_ratio * j) -x
y_diff = (y_ratio * i) - y
'calculations for red, green and blue
a = oldSurf.Pixel(x, y)
b = oldSurf.Pixel(x + 1, y)
c = oldSurf.Pixel(x, y + 1)
d = oldSurf.Pixel(x + 1, y + 1)
blue = (a.Blue * (1 - x_diff) * (1 - y_diff)) + (b.Blue * x_diff * (1 - y_diff)) + (c.Blue * y_diff * (1 - x_diff)) + (d.Blue * x_diff * y_diff)
green = (a.green * (1 - x_diff) * (1 - y_diff)) + (b.green * x_diff * (1 - y_diff)) + (c.green * y_diff * (1 - x_diff)) + (d.green * x_diff * y_diff)
red = (a.red * (1 - x_diff) * (1 - y_diff)) + (b.red * x_diff * (1 - y_diff)) + (c.red * y_diff * (1 - x_diff)) + (d.red * x_diff * y_diff)
InterpolatedSurf.Pixel(j, i) = RGB(red, green, blue)
if oldMaskSurf <> Nil then
'now the mask
a = oldMaskSurf.Pixel(x, y)
b = oldMaskSurf.Pixel(x + 1, y)
c = oldMaskSurf.Pixel(x, y + 1)
d = oldMaskSurf.Pixel(x + 1, y + 1)
gray = (a.Blue * (1 - x_diff) * (1 - y_diff)) + (b.Blue * x_diff * (1 - y_diff)) + (c.Blue * y_diff * (1 - x_diff)) + (d.Blue * x_diff * y_diff)
InterpolatedMaskSurf.Pixel(j, i) = RGB(gray, gray, gray)
end if
next
next
Return InterpolatedPicture
End Function[/code]