当前位置: 首页 > article >正文

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);
在这里插入图片描述


http://www.kler.cn/a/272461.html

相关文章:

  • 鸿蒙应用开发之流式网络布局
  • 第十四届蓝桥杯省赛
  • uni-segmented-control在微信小程序中不显示
  • 【LabVIEW FPGA入门】浮点数类型支持
  • python--常用简单功能
  • 阿里云下载安装centos
  • 【02】JavaScript基础
  • 【JAVA笔记】IDEA配置本地Maven
  • JAVA代理模式梳理
  • 如何在 iPhone 上使用蓝牙鼠标
  • 【系统性】 循序渐进学C++
  • 【tls招新web部分题解】
  • 惠海 H6213E 降压恒压芯片 12V24V36V48V60V72V100V150V 转12V9V5V3.3V 车充/仪表供电方案IC
  • Linux环境下用IDEA运行Golang记录
  • SAR ADC教程系列5——FFT频谱泄露以及相干采样
  • el-input设置max、min无效的解决方案
  • VSCODE的常用插件
  • QTextToSpeech的使用——Qt
  • python中pyinstaller打包带资源的程序-pgzreo
  • 修复cython使用的bug,在mac上实现了编译,整理了cython和numba等加速文件,提供了一键编译