我已经使用Qt4实现了一个字幕文本小部件。我首先将文本内容绘制到一个像素图上。然后通过调用painter.drawTiledPixmap(offsetX,offsetY,myPixmap)将这个像素图的一部分绘制到绘制设备上
我的设想是,Qt将用来自myPixmap的内容填充整个字幕文本矩形。
有没有更快的方法,将所有现有内容左移1px,然后用来自myPixmap的内容填充新曝光的1px宽和N-px高的区域?
发布于 2010-05-09 04:00:37
井。这是我在过去对较慢的硬件所做的一个技巧。基本上,图像缓冲区分配的宽度是所需宽度的两倍,并且在开始时增加了1行。在缓冲区的左侧构建图像。然后重复绘制图像,缓冲区在缓冲区中一次前进1个像素。
int w = 200;
int h = 100;
int rowBytes = w * sizeof(QRgb) * 2; // line buffer is twice as the width
QByteArray buffer(rowBytes * (h + 1), 0xFF); // 1 more line than the height
uchar * p = (uchar*)buffer.data() + rowBytes; // start drawing the image content at 2nd line
QImage image(p, w, h, rowBytes, QImage::Format_RGB32); // 1st line is used as the padding at the start of scroll
image.fill(qRgb(255, 0, 0)); // well. do something to the image
p = image.bits() - rowBytes / 2; // start scrolling at the middle of the 1st (blank) line
for(int i=0;i<w;++i, p+=sizeof(QRgb)) {
QImage scroll(p, w, h, rowBytes, QImage::Format_RGB32); // scrool 1 pixel at a time
scroll.save(QString("%1.png").arg(i));
}我不确定这是否会比仅仅改变图像的偏移量并绘制它更快。今天的硬件真的很强大,这使得许多老把戏变得毫无用处。但是玩一些晦涩的把戏很有趣。:)
发布于 2010-04-26 20:54:58
大家好,
实现这一目标的一种可能性是:
<代码>G29
这可能会更快,也可能不会更快(就性能而言)--我还没有测试过。但如果只是为了实验,可能值得一试。
发布于 2010-05-05 20:03:13
您的方法可能是最快的方法之一,因为您使用的是低级绘制方法。您可以在低级绘制和QGraphicsScene选项之间实现一种中间方法:使用包含标签的滚动区域。
下面是创建包含文本标签的新滚动区域的代码示例。您可以使用QTimer自动滚动标签以触发滚动效果,这将为您提供一个很好的字幕小部件。
QScrollArea *scrollArea = new QScrollArea();
// ensure that scroll bars never show
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QLabel *label = new QLabel("your scrolling text");
// resize the scroll area : 50px length and an height equals to its content height.
scrollArea->resize(50, label->size().height());
scrollArea->setWidget(label);
label->show(); // optionnal if the scroll area is not yet visible使用带有等于-1的dx参数的QScrollArea::scrollContentsBy(int dx, int dy),可以将滚动区域内的文本标签从左向右移动一个像素。
https://stackoverflow.com/questions/2712003
复制相似问题