douyouyi8878 2019-01-11 16:30
浏览 1082

QML QT的grabToImage获取图像字节

For some reason, saving a png back out from qml directly doesn't work. I have a qml UI on top of a Golang application. When I do

source.grabToImage(function(result){
    console.log("image: ", result.url)
if (!result.saveToFile(urlNoProtocol)){
    console.error('Unknown error saving to',urlNoProtocol);
} else {
    console.log("saved to " + urlNoProtocol)
}

I get an error saving out. The location to save the file is coming from a fileDialog and I preprocess it to remove the file:// which I understand needs to be removed before using saveToFile. However I get an unknown error saving from the above code.

I suspect this is something to do with the qml being embedded in the binary application (perhaps to do with qrc:// or something)

Anyway my current plan is to send the image to the golang backend and save it out from there, so my question is, how from grabToImage or saveToFile can I get the image bytes that I will then save?

N.B Using therecipe/qt for the interface between Golang and qml

  • 写回答

1条回答 默认 最新

  • doubengshao8872 2019-01-11 16:52
    关注

    I have used this method for grabbing screen shots..

    function performScreenShot(item, name) {
        if(typeof(item) === "undefined") {
            return;
        }
        else if(typeof(name) !== "string") {
            name = "screenshot.png"
        }
    
        item.grabToImage(function(result) {
            result.saveToFile(name);
        });
    }
    

    Usage example:-

    performScreenShot(main, "screenshot-" + screenShotIndex + ".png")
    

    Where main is my object id and screenShotIndex is something im incrementing so as not to override any previous capture.

    Ensure that you have write permission on the device.

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题