c++ - 如何在移动滑块的同时连续加载和显示多个图像?
问题描述
我正在使用 c++ 在 Qt 中的图像查看器中创建一个函数,其中可以在移动滑块的同时加载和显示多个图像。我可以参考任何想法或代码参考吗?谢谢你。
void MainWindow::on_btn_image_clicked()
{
qDebug()<<"clicked.....";
QStringList filename = QFileDialog::getOpenFileNames(this, tr("Browse Image"), "", tr("Images(*.png *.jpg *.bmp *.gif)"));
if (!filename.isEmpty())
{
for(int i=0; i<filename.length(); i++)
{
QString str = filename.at(i) ;
qDebug()<<"str========>>>>>"<<str;
QImage image1(str);
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
image1.save(&buffer,"");
buffer.close();
unsigned char *data_image = (unsigned char *)malloc(bytes.size());
memcpy(data_image, reinterpret_cast<unsigned char *>(bytes.data()), (unsigned int)bytes.size());
auto sigMap = new QSignalMapper(this);
horizontalSlider[i] = new QSlider(this);
connect(horizontalSlider[i], SIGNAL(valueChanged(int)), sigMap, SLOT(map()));
sigMap->setMapping(horizontalSlider[i], i);
connect(sigMap, SIGNAL(mapped(int)), this, SLOT(slider_x(int)));
int h=image1.height();
int w=image1.width();
QImage image2(str);
image2= QImage(data_image, h, w, QImage::Format_Indexed8);
if (image2.height()>=image2.width())
{
image = image2.scaledToHeight(ui->graphicsView->height(), Qt::SmoothTransformation);
}
else
{
image = image2.scaledToWidth(ui->graphicsView->width(), Qt::SmoothTransformation);
}
item = new QGraphicsPixmapItem(QPixmap::fromImage(image));
scene[i] = new QGraphicsScene(this);
ui->graphicsView->setScene(scene[i]);
scene[i]->addItem(item);
}
}
}
void MainWindow::slider_x(int i)
{
int value = horizontalSlider[i]->value();
}
我正在尝试将图像转换为字节数组并将数组自动连接到滑块。概念或代码有什么问题吗?
解决方案
我的方法是在一个 flickable 中加载布局中的所有图像,并将 flickable 与滑块连接起来。您可以选择以下图片在屏幕外加载的方式的布局,这样您就可以在窗口/屏幕上移动一个图像栏。但是,当图片数量变大时,这可能会变得非常耗费资源。如果您正在处理大量图像,您应该按需加载它们,并在它们离开屏幕时卸载它们。但是使用这种方法,我不确定如何处理项目/对象。
推荐阅读
- opencv - 缺少 OpenCvSharp.CvConst 类?
- matlab - 如果一个轴上的距离低于某个阈值,则连接绘图中的点
- java - 卡力技巧。如何完成完美的 shuffle 或 riffle shuffle
- r - 使用 ggplot2 绘制每个队列的工作状态?
- python - 文档图像研究论文和测试集的歪斜校正
- text - Power Query:如何提取符号前后指定数量的字符?
- python - 如何在matplotlib pyplot中显示超过计数顺序?
- html - HTML/CSS,只有当元素内容的高度 > 0 时,元素才具有顶部和底部边距(或填充)
- java - 使用 @ManyToMany 反序列化和持久化
- javascript - 电子邮件地址格式错误