Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Printing grabToImage (rounded pictures)

Printing grabToImage (rounded pictures)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 297 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leon_2001
    wrote on last edited by
    #1

    Hi everyone,

    I need to create some IDs with picture, names etc. ... about 8 ids should be printed on one DINA4 paper.
    My current approach is using "grabToImage"

    var component = Qt.createComponent("IdLayout.qml");
    var idLayout = idLayout = component.createObject(root, {"model": root.model});
    var stat = idLayout.grabToImage(function(result) {
       result.saveToFile("ausweise.png");
    });
    console.log("Success: ", stat);
    

    It kinda seems to work except from the fact that I don't know how IdLayout has the perfect size of DINA4 ... but with a little bit of try and error this works.
    The only problem seem to be rounded Images. The common approach with layers doesn't work with grabToImage for some reason ...

                Image {
                  id: img
                  Layout.alignment: Qt.AlignHCenter
                  Layout.preferredWidth: 100
                  Layout.preferredHeight: 100
    
                  source: '../Images/user.png'
                  fillMode: Image.PreserveAspectCrop
                  layer.enabled: true
                  layer.effect: OpacityMask {
                      maskSource: mask
                  }
    
                  Rectangle {
                    id: mask
                    width: 100
                    height: 100
                    radius: 50
                    visible: false
                  }
                }
    

    Any reason why grabToImage doesn't work with grabToImage()?

    So my next approach canvas seem to work only with some pictures

            Canvas {
              width: 120
              height: 120
    
              onPaint: {
                var ctx = getContext("2d");
                // store current context setup
                ctx.save()
                ctx.strokeStyle = '#ff2a68'
                ctx.beginPath()
                ctx.roundedRect(0, 0, 120, 120, 60, 60)
                ctx.closePath()
                // create clip from the path
                ctx.clip()
                // draw image with clip applied
                ctx.drawImage(pfad, 0, 0, 120, 120)
                ctx.stroke();
                // restore previous context
                ctx.restore()
              }
    
              Component.onCompleted: {
                loadImage(pfad);
              }
    
              onImageLoaded: {
                requestPaint();
              }
            }
    

    the stroke is just for testing purposes.
    I have at least two pictures (one png, one jpeg), which work perfectly with that (also mixed) -> pfad is a model attribute (it's the path).
    With all the pictures from my camera, which are jpg (and one other jpeg) it doesn't work. I'm pretty sure the paths are all correct! Because if I just use an Image instead it works perfectly.

    So has anyone an idea why those approaches with rounded pictures don't work or only partly? Or has another solution?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved