gpt4 book ai didi

c++ - 如何翻转 QImage

转载 作者:太空狗 更新时间:2023-10-29 20:58:08 25 4
gpt4 key购买 nike

翻转/镜像 QImage 的正确方法是什么?以下代码段不起作用。

 //allocate buffer
BYTE* pRgb32Buffer = new BYTE[width*height* 4];
//create paint device
QImage img = QImage(pRgb32Buffer , width, height, getStride(width, pixelFormat), QImage::Format_RGB32);
//do some drawing on image (works!)
QPainter painter(&img);
painter.drawText(10, 50, QString("some text"));
//mirrore image (doesn't mirror the orignal buffer!!!)
img = img.mirrored(false,true);
//doesn't work either
//QImage mirrored = img.mirrored();
//img = mirrored;
//mirrored.detach();

最佳答案

使用 QImage::mirrored() 的解决方案:

memmove(pRgb32Buffer, img.mirrored().bits(),img.byteCount());

关于c++ - 如何翻转 QImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28409248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com