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. Image vs VectorImage for SVG. What to use?
Qt 6.11 is out! See what's new in the release blog

Image vs VectorImage for SVG. What to use?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 376 Views 1 Watching
  • 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.
  • B Offline
    B Offline
    bogong
    wrote last edited by
    #1

    Hello all!

    What is better to use with SVG? VectorImage? Or just Image?

    Both is working on devices (iOS/Android) and MacOS, but on Android simulator started showing black square instead of rendered Image with SVG source (after update on MacOS Sequoia). On physical Android device all is Ok, both equal (VectorImage and Image).

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bogong
      wrote last edited by
      #2

      The black square were because conflict of macOS Sequoia (Apple Silicon) hardware acceleration in the Android emulator with Qt's RHI (Rendering Hardware Interface). Changing settings in Android emulator solved black square problem.

      Open your AVD Manager in Android Studio, edit your Virtual Device, and change the Graphics setting from Automatic/Hardware to Software

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SimonSchroeder
        wrote last edited by
        #3

        Vector-based formats are usually superior to pixel-based formats. SVG is a vector format, so it is generally preferable to use a vector image. This allows the image to scale properly to different screen sizes.

        1 Reply Last reply
        2
        • EskilE Offline
          EskilE Offline
          Eskil
          wrote last edited by
          #4

          Unfortunately, one is not decisively better than the other, or we would not have included both. It depends on the use case you have in mind. If the target size of the image is known at build time, then I would usually recommend converting it to a PNG as part of the build process and showing it with an Image component. Drawing a prerasterized image is as fast as it gets.

          If your application is running on multiple form factors and therefore needs to be able to render the image at arbitrary sizes, this approach becomes impratical. But if the target size is selected at startup of the application and stays the same for its duration, then including the SVG file and rendering it with an Image will likely be best. There is a cost to rasterize the SVG the first time it is loaded, but otherwise this performs the same as rendering a PNG.

          If you need to transform the image while the application is running (for instance doing animated zooms like in the Weather Forecast example: https://doc.qt.io/qt-6/qtquick-quickshapes-weatherforecast-example.html) then the best option currently is VectorImage. The same goes if the SVG is animated.

          As an additional point: If the SVGs are rasterized at very large sizes, then VectorImage will typically be more conservative of memory. So it can also depend on which resource you want to conserve.

          Some notes about this from the documentation: https://doc.qt.io/qt-6/topics-graphics2d.html#prerasterized-vector-images

          1 Reply Last reply
          3
          • S Offline
            S Offline
            SimonSchroeder
            wrote last edited by
            #5

            I agree that for fixed sizes PNG is the better format. However, for mobile devices in a lot of cases the size is not fixed. Maybe I have assumed too much 😉. Even on desktop we tend to use SVG for icons because of display scaling (though as far as I know if you have a dedicated designer he should design PNGs for different resolutions instead).

            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