通过 QDialog 加载 sf::Image
Loading sf::Image by QDialog
是否有使用 QDialog 或其他库加载 sf::Image 的简便方法?我的意思是我想通过 "Choose image..." window.
加载图像以便在 sfml 中使用它
您可以使用QFileDialog获取给定图片的路径:
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
QDir::currentDirPath() ,
tr("Images (*.png *.xpm *.jpg)"));
if (!fileName.isEmpty()) {
// Now you can init your sf::image
}
根据SFML, you can use the loadFromFile函数的官方文档
sf::Image image;
if (image.loadFromFile(filename.toStdString())) {
std::cout << "image loaded with success";
}
是否有使用 QDialog 或其他库加载 sf::Image 的简便方法?我的意思是我想通过 "Choose image..." window.
加载图像以便在 sfml 中使用它您可以使用QFileDialog获取给定图片的路径:
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
QDir::currentDirPath() ,
tr("Images (*.png *.xpm *.jpg)"));
if (!fileName.isEmpty()) {
// Now you can init your sf::image
}
根据SFML, you can use the loadFromFile函数的官方文档
sf::Image image;
if (image.loadFromFile(filename.toStdString())) {
std::cout << "image loaded with success";
}