有人用VC做过对真彩色图片进行几何变换(缩放、平移、旋转)的吗?
解决方案 »
- 往虚拟磁盘里写数据会造成NTFS错误
- 动态创建CView,结束程序时出现问题
- OpenGL里纹理映射函数最后一个参数
- 如何把从系统提取的时间保存为sql数据库中的datetime格式
- 如何向已存在的实例传递参数
- 头文件 .h, .hpp有什么区别呀?
- 如何将int型的变量转化为LPCTSTR类型的?
- 这个问题如何解决呀?“error MIDL2041 : [out] only parameter cannot be an unsized string : [ Type 'LPTSTR' ( Parameter 'a_Text' )
- atl制作com 编译Win32 Release MinDependency 出现以下问题 求解。
- dll跟踪调试问题
- 郁闷,昨天我发布一个VC程序给客户,但是程序 release 版却弹框,debug 版本没问题,所以我也没办法跟踪,最后只好换了一种方法实现功能
- 怎样获取当前目录及其上一级目录?在线等
我曾经写过所有位深的处理,给你一个例子,只是关键部分代码
缩放:(最简单的那种) if (nBitCount == 24)
{
RGBTRIPLE *pSrc, *pDst;
for(j = 0; j < nNewHeight; j++)
{
pDst = (RGBTRIPLE *)(pdesBits + ndesLineBytes * (nNewHeight-1-j));
oj = (int) ((j+1) / fYRatio - 0.5);
ASSERT((oj >= 0) && (oj < nHeight));
pSrc = (RGBTRIPLE *)(psrcBits + nsrcLineBytes * (nHeight-1-oj)); for(i = 0; i < nNewWidth; i++)
{
oi = (int) ((i+1) / fXRatio - 0.5);
ASSERT((oi >= 0) && (oi < nWidth));
pDst[i] = pSrc[oi];
}
}
}
else if (nBitCount == 32)
{
ULONG *pSrc, *pDst;
for(j = 0; j < nNewHeight; j++)
{
pDst = (ULONG *)(pdesBits + ndesLineBytes * (nNewHeight-1-j));
oj = (int) ((j+1) / fYRatio - 0.5);
ASSERT((oj >= 0) && (oj < nHeight));
pSrc = (ULONG *)(psrcBits + nsrcLineBytes * (nHeight-1-oj)); for(i = 0; i < nNewWidth; i++)
{
oi = (int) ((i+1) / fXRatio - 0.5);
ASSERT((oi >= 0) && (oi < nWidth));
pDst[i] = pSrc[oi];
}
}
}
else if (nBitCount == 16)
{
USHORT *pSrc, *pDst;
for(j = 0; j < nNewHeight; j++)
{
pDst = (USHORT *)(pdesBits + ndesLineBytes * (nNewHeight-1-j));
oj = (int) ((j+1) / fYRatio - 0.5);
ASSERT((oj >= 0) && (oj < nHeight));
pSrc = (USHORT *)(psrcBits + nsrcLineBytes * (nHeight-1-oj)); for(i = 0; i < nNewWidth; i++)
{
oi = (int) ((i+1) / fXRatio - 0.5);
ASSERT((oi >= 0) && (oi < nWidth));
pDst[i] = pSrc[oi];
}
}
}
else if (nBitCount == 8)
{
UCHAR *pSrc, *pDst;
for(j = 0; j < nNewHeight; j++)
{
pDst = pdesBits + ndesLineBytes * (nNewHeight-1-j);
oj = (int) ((j + 1) / fYRatio - 0.5);
ASSERT((oj >= 0) && (oj < nHeight));
pSrc = psrcBits + nsrcLineBytes * (nHeight-1-oj); for(i = 0; i < nNewWidth; i++)
{
oi = (int) ((i + 1) / fXRatio - 0.5);
ASSERT((oi >= 0) && (oi < nWidth));
pDst[i] = pSrc[oi];
}
}
}
else if (nBitCount == 4)
{
PUCHAR pTempDst,pTempSrc,pDst,pSrc;
for(j = 0; j < nNewHeight; j++)
{
pTempDst = pdesBits + ndesLineBytes * (nNewHeight-1-j);
oj = (int) ((j + 1) / fYRatio - 0.5);
ASSERT((oj >= 0) && (oj < nHeight));
pTempSrc = psrcBits + nsrcLineBytes * (nHeight - 1 - oj); for(i = 0; i < nNewWidth; i++)
{
oi = (int) ((i + 1) / fXRatio - 0.5);
ASSERT((oi >= 0) && (oi < nWidth)); pDst = pTempDst + (i >> 1);
pSrc = pTempSrc + (oi >> 1); switch ((i & 1) | ((oi & 1) << 1))
{
case 0: *pDst = *pSrc | 15; break;
case 1: *pDst &= (*pSrc >> 4) | 240; break;
case 2: *pDst = (*pSrc << 4) | 15; break;
case 3: *pDst &= *pSrc | 240;
}
}
}
}
else if (nBitCount == 1)
{
UCHAR uc1bit;
PUCHAR pTempDst,pTempSrc,pDst,pSrc;
for(j = 0; j < nNewHeight; j++)
{
pTempDst = pdesBits + ndesLineBytes * (nNewHeight-1-j);
oj = (int) ((j + 1) / fYRatio - 0.5);
ASSERT((oj >= 0) && (oj < nHeight));
pTempSrc = psrcBits + nsrcLineBytes * (nHeight-1-oj); for(i = 0; i < nNewWidth; i++)
{
oi = (int) ((i + 1) / fXRatio - 0.5);
ASSERT((oi >= 0) && (oi < nWidth)); pDst = pTempDst + (i >> 3);
pSrc = pTempSrc + (oi >> 3); uc1bit = (*pSrc >> (7 - (oi & 7))) & 1; switch (i & 7)
{
case 0: *pDst = (uc1bit << 7) | 127; break;
case 1: *pDst &= (uc1bit << 6) | 191; break;
case 2: *pDst &= (uc1bit << 5) | 223; break;
case 3: *pDst &= (uc1bit << 4) | 239; break;
case 4: *pDst &= (uc1bit << 3) | 247; break;
case 5: *pDst &= (uc1bit << 2) | 251; break;
case 6: *pDst &= (uc1bit << 1) | 253; break;
case 7: *pDst &= uc1bit | 254;
}
}
}
}
{
RGBTRIPLE *pSrc, *pDst;
for(j = 0; j < nNewHeight; j++)
{
pDst = (RGBTRIPLE *)(pdesBits + ndesLineBytes * (nNewHeight-1-j));
oj = (int) ((j+1) / fYRatio - 0.5);
ASSERT((oj >= 0) && (oj < nHeight));
pSrc = (RGBTRIPLE *)(psrcBits + nsrcLineBytes * (nHeight-1-oj)); for(i = 0; i < nNewWidth; i++)
{
oi = (int) ((i+1) / fXRatio - 0.5);
ASSERT((oi >= 0) && (oi < nWidth));
pDst[i] = pSrc[oi];
}
}
}实在不好意思,小弟现在是才鸟一个,这些变换的原理不复杂,可是用VC来实现,小弟现在真是一筹莫展,上面这段代码是对24位彩色图片进行缩放变换的吗?
比如:nHeight是指变换前的图像高,nNewHeight是指变换后的图像高,nsrcLineBytes是指变换前的图像字节宽(4字节对齐规则),等等。注意,变换前后的图像内存不能是同样的。也就是说,你得自己构造目标图像的内存空间。