有人用VC做过对真彩色图片进行几何变换(缩放、平移、旋转)的吗?

解决方案 »

  1.   

    这个很难吗?
    我曾经写过所有位深的处理,给你一个例子,只是关键部分代码
    缩放:(最简单的那种)    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;
                    }
                }
            }
        }
      

  2.   

    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];
                }
            }
        }实在不好意思,小弟现在是才鸟一个,这些变换的原理不复杂,可是用VC来实现,小弟现在真是一筹莫展,上面这段代码是对24位彩色图片进行缩放变换的吗?
      

  3.   

    是,但你不能直接用。因为好多变量需要你来实时获得。不过我的命名应该很清楚吧?
    比如:nHeight是指变换前的图像高,nNewHeight是指变换后的图像高,nsrcLineBytes是指变换前的图像字节宽(4字节对齐规则),等等。注意,变换前后的图像内存不能是同样的。也就是说,你得自己构造目标图像的内存空间。