【问题标题】:How to merge two images in qt after mirroring mode?镜像模式后如何在qt中合并两个图像?
【发布时间】:2015-03-30 17:52:37
【问题描述】:

我需要镜像一个图像。我已经完成了那部分,但是当调用这个函数时,原始图像在我的图像区域中消失了。我保存了原始图像并使用 QPainter 绘制了原始图像,然后绘制了镜像,我认为这两个图像都会被合成。我仍然只得到镜像。我想要一个图像区域上的镜像和原始图像。这是我目前所拥有的。

QImage* Original= mImage; //original image
QImage reflection = mImage->mirrored(true,false);//mirror the original image

QPainter painter(mImage);

painter.CompositionMode_DestinationOver;
painter.drawImage(0, 0, *mImage);
painter.drawImage(0, 0, reflection);
painter.end();

【问题讨论】:

    标签: qt qpainter qimage


    【解决方案1】:

    QPainter::CompositionMode_DestinationOver

    目标的 alpha 用于将其混合到源之上 像素。

    如果您的图像没有 Alpha 通道,您将看不到任何差异。

    此外,您的代码中还有其他问题。

    • 无需在自身上绘制图像
    • painter.end(); 是不必要的
    • 使用painter.setCompositionMode();设置合成模式
    • 构图模式在图纸之间设置


    QPainter painter(mImage);
    painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
    painter.drawImage(0, 0, reflection);
    

    【讨论】:

    • 谢谢,我创建了一个 Alpha 通道,但现在镜像不起作用QImage mask = mImage->createAlphaMask(); QPainter painter(&mask);
    • 您还需要具有明显透明度的像素。
    猜你喜欢
    • 2021-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    • 2020-06-22
    • 2011-01-20
    相关资源
    最近更新 更多