r (UINT i = 0; i < outWidth; i++)
{
y = i;
copyPixel = pixel + y * width * 4 + x * 4;
objPixel = tempPixel + tempJ + i * 4;
memcpy(objPixel, copyPixel, 4);
}
}
}
/******************************************************************************
* 作用: 图像的缩放函数(最临近插值法)
* 参数:
* pixel 原始像素数组
* tempPixel 保存变换后图像的像素数组
* width 原始图像宽度
* height 原始图像高度
* outWidth [out]输出图像的宽度
* outHeight [out]输出图像的高度
* fx 水平缩放系数
* fy 垂直缩放系数
******************************************************************************/
void ZoomNormal(BYTE* pixel, BYTE*& tempPixel, int width, int height,
UINT& outWidth, UINT& outHeight, double fx, double fy)
{
// 计算缩放后的图像大小
outWidth = (UINT)(width * fx);
outHeight = (UINT)(height * fy);
int size = outWidth * outHeight * 4;
tempPixel = new BYTE[size];
memset(tempPixel, 255, size);
BYTE* copyPixel = NULL; // 指向原始图像中需要拷贝像素的起始位置
BYTE* objPixel = NULL; // 指向被复制像素的起始位置
int x = 0; // 变换后的像素横坐标
int y = 0; // 变换后的像素纵坐标
long tempY; // 存储中间值,提高函数速度
long tempJ; // 存储中间值,提高函数速度
for (UINT j = 0; j < outHeight; j++)
{
// 获得临近像素的纵坐标
y = (int)(j / fy + 0.5);
// 修正坐标
if (y >= height)
y--;
// 计算与i,x无关的中间值
tempY = y * width * 4;
tempJ = j * outWidth * 4;
for (UINT i = 0; i < outWidth; i++)
{
// 获得临近像素的横坐标
x = (int)(i / fx + 0.5);
// 修正坐标
if (x >= width)
x--;
copyPixel = pixel + tempY + x * 4;
objPixel = tempPixel + tempJ + i * 4;
memcpy(objPixel, copyPixel, 4);
}
}
}
/******************************************************************************
* 作用: 图像的缩放函数(双线性插值法)
* 参数:
* pixel 原始像素数组
* tempPixel 保存变换后图像的像素数组
* width 原始图像宽度
* height 原始图像高度
* outWidth [out]输出图像的宽度
* outHeight [out]输出图像的高度
* fx 水平缩放系数
* fy 垂直缩放系数
******************************************************************************/
void ZoomInterpolation(BYTE* pixel, BYTE*& tempPixel, int width, int height,
UINT& outWidth, UINT& outHeight, double fx, double fy)
{
// 计算缩放后的图像
上一篇:
geom.cpp
下一篇:
对近年来中国经济过热的初步分析