Unify the code samples to use QImage

This commit is contained in:
Martin Tůma 2023-12-11 11:40:18 +01:00 committed by GitHub
parent f5f006dc7b
commit d8a521623a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,19 +18,19 @@ to fit the styles and available data (OpenMapTiles, Mapbox tiles).
Due to a major design flaw in the Mapbox vector tiles specification - the zoom Due to a major design flaw in the Mapbox vector tiles specification - the zoom
is not part of the PBF data - the plugin can not be used "as is", but passing is not part of the PBF data - the plugin can not be used "as is", but passing
the zoom level is necessary. This is done by exploiting the optional *format* the zoom level is necessary. This is done by exploiting the optional *format*
parameter of the QImage constructor or the QImage::fromData() or parameter of the QImage constructor or the *QImage::loadFromData()* or
QPixmap::loadFromData() functions. The zoom number is passed as ASCII string *QPixmap::loadFromData()* functions. The zoom number is passed as ASCII string
to the functions: to the functions:
```cpp ```cpp
QPixmap pm; QImage img;
pm.loadFromData(data, QByteArray::number(zoom)); img.loadFromData(data, QByteArray::number(zoom));
``` ```
For a complete code sample see the [pbf2png](https://github.com/tumic0/pbf2png) For a complete code sample see the [pbf2png](https://github.com/tumic0/pbf2png)
conversion utility. conversion utility.
### HiDPI ### HiDPI
The plugin supports vector scaling using QImageReader's setScaledSize() method, The plugin supports vector scaling using QImageReader's *setScaledSize()* method,
so when used like in the following example: so when used like in the following example:
```cpp ```cpp
QImage img; QImage img;
@ -44,9 +44,9 @@ you will get 1024x1024px tiles with a pixel ratio of 2 (= HiDPI tiles).
Since version 3 of the plugin tile overzoom is supported. If you set *format* Since version 3 of the plugin tile overzoom is supported. If you set *format*
to `$zoom;$overzoom`: to `$zoom;$overzoom`:
```cpp ```cpp
QPixmap pm; QImage img;
QByteArray fmt(QByteArray::number(zoom) + ';' + QByteArray::number(overzoom)); QByteArray fmt(QByteArray::number(zoom) + ';' + QByteArray::number(overzoom));
pm.loadFromData(data, fmt); img.loadFromData(data, fmt);
``` ```
you will get (512<<overzoom)x(512<<overzoom)px tiles with a pixel ratio of 1. you will get (512<<overzoom)x(512<<overzoom)px tiles with a pixel ratio of 1.
When overzoom is combined with setScaledSize(), the base size is the overzoomed When overzoom is combined with setScaledSize(), the base size is the overzoomed