Cross-Platform Command-Line Utilities for HVIF & SVG Conversion

Hi @3dEyes and all forum readers - I’m wondering if it’s possible to try use this utility to convert the icon of an App (or folder) to svg format in run-time in my HiQDock app.

My current implementation uses the following code to read the app’s icon data and converts it into a base64 png uri and then the Qml code can read that png data as the source for the image.

Users can later add an .svg file to be the App’s icon on the dock launcher, but I would prefer to use the real hvif icon in the app resource as the ‘svg’ file so that it scales up / down smoothly (instead of this current .png implementation which is low-res / pixelated scaling)

here’s my current code:

QString MainWindow::getIconBase64UriForFile(const QString &appSignatureString)
{

entry_ref ref;
status_t stat = be_roster->FindApp(appSignatureString.toLatin1().data(), &ref);

QString fileFullPath;

if (stat == B_OK)
{
    BEntry myBEntry(&ref, TRUE);

    char name[B_FILE_NAME_LENGTH];
    myBEntry.GetName(name);
    myBEntry.GetParent(&myBEntry);
    BPath P;
    myBEntry.GetPath(&P);
    fileFullPath = QString(P.Path()) + "/" + QString(name);
}
else //probably not an app but a regular file or directory
{
    QFileInfo fileInfo(appSignatureString);
    if (fileInfo.exists()) {
          fileFullPath = appSignatureString;
    }
    else {
        return "";
    }
}

QFileInfo qFileInfo(fileFullPath);

QFileIconProvider iconProvider;
QIcon theIcon = iconProvider.icon(qFileInfo);
QByteArray byteArray;
QBuffer    buffer(&byteArray);
buffer.open(QIODevice::WriteOnly);
theIcon.pixmap(QSize(32, 32), QIcon::Normal, QIcon::On).save(&buffer, "PNG");
QString iconBase64 = QString(byteArray.toBase64());
return "data:image/png;base64," + iconBase64;
}

Any thoughts?
Note: assumption that qml code must have an .svg file for image source - I don’t think it can read/render/scale hvif format

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论