0
点赞
收藏
分享

微信扫一扫

【Express.js】页面渲染

左小米z 2023-08-12 阅读 41

1.基本原理

    1.水平镜像变化

    设图像的宽度为width,则水平镜像变化的映射关系如下:

    2.垂直镜像变化

    设图像的宽度为height,则垂直镜像变化的映射关系如下:

2.代码实现(代码是我以前自学图像处理时写的,代码很粗糙没做任何优化,但很好理解

/*水平镜像变换函数*/
QImage* MainWindow::HMirrorTrans(QImage* image)
{
    QImage* newImage = new QImage(image->width(),image->height(),QImage::Format_ARGB32);
    //方法1:通过映射关系进行变换
    int x = 0;
    int y = 0;
    unsigned char* copyPixel = NULL;
    unsigned char* objPixel = NULL;

    for (int j = 0; j< image->height(); j++)
    {
        y = j;
        for(int i = 0; i < image->width(); i++)
        {
            x = image->width() - i - 1;
            copyPixel = image->bits() + j * image->width() * 4 + i * 4;
            objPixel = newImage->bits() + y * image->width() * 4 + x * 4;

            memcpy(objPixel,copyPixel,4);
        }
    }
    return newImage;
}

/*垂直镜像变换函数*/
QImage* MainWindow::VMirrorTrans(QImage* image)
{
    QImage* newImage = new QImage(image->width(),image->height(),QImage::Format_ARGB32);
    //方法1:通过映射关系进行变换
    int x = 0;
    int y = 0;
    unsigned char* copyPixel = NULL;
    unsigned char* objPixel = NULL;

    for (int j = 0; j< image->height(); j++)
    {
        y = image->height() - j - 1;
        for(int i = 0; i < image->width(); i++)
        {
            x = i;
            copyPixel = image->bits() + j * image->width() * 4 + i * 4;
            objPixel = newImage->bits() + y * image->width() * 4 + x * 4;

            memcpy(objPixel,copyPixel,4);
        }
    }
    return newImage;
}

3.参考资料

    数字图像处理——技术详解与Visual C++实践(左飞等著),写代码与写博客的时间相差两年,至于还参考其他的资料不,我已经忘记了,如若需要,我可以补上去

举报

相关推荐

0 条评论