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

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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题