8-图像缩放

其实,就是开辟一个zoomwidth,zoomheight的内存,再分别赋值即可。

void CDib::Scale(float xZoom, float yZoom)
{
//指向原图像指针
LPBYTE p_data = GetData();
//指向原像素的指针
LPBYTE lpSrc;
//指向缩放图像对应像素的指针
LPBYTE lpDst ;
//像素在原DIB的坐标
LONG i;
LONG j;
//循环变量(像素在新图中的坐标)
LONG i0;
LONG j0;
//图像的宽和高
LONG width = GetWidth();
LONG height = GetHeight();
//计算放缩后的图像宽度和高度
LONG newWidth = (LONG)(width * xZoom + 0.5);
LONG newHeight = (LONG)(height * yZoom + 0.5);
LONG newLineBytes = (newWidth * 8 + 31) / 32 * 4;
//暂时分配内存,以保存新图像
LPBYTE temp1 = new BYTE[newWidth * newHeight];
memset(temp1, (BYTE)255, newWidth * newHeight);
int r, g, b;
for (int i = 0; i < newWidth; i++)
{
for (int j = 0; j < newHeight; j++)
{
lpDst = (LPBYTE)temp1 + newWidth * j + i;
int i0 = (i / xZoom + 0.5);
int j0 = (j / yZoom + 0.5);
if ((i0 >=0 ) && ( i0 < width) && (j0 >= 0) && (j0 < height))
{
lpSrc = (LPBYTE)p_data + width * j0 + i0;
*lpDst = *lpSrc;
}
}
}
m_pData = temp1;
m_pBitmapInfoHeader->biWidth = newWidth;
m_pBitmapInfoHeader->biHeight = newHeight;

}
构造函数调用

CMy1_showbitmapView::CMy1_showbitmapView()
{
_cdib.LoadFile (“D:/Test/DataProcess/result.bmp”);
_cdib.Scale(2.0, 2.0);
}
在这里插入图片描述
如果改为0.5倍,即
_cdib.Scale(0.5, 0.5);
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值