Scaling pixel art with Qt Quick

喜欢而已 提交于 2019-12-07 08:41:06

问题


I have a Qt Quick game that uses pixel art. For example:

import QtQuick 2.2
import QtQuick.Controls 1.1

ApplicationWindow {
    id: window
    visible: true
    width: 300
    height: 300
    title: qsTr("PixelArt")

    Image {
        source: "http://upload.wikimedia.org/wikipedia/commons/f/f0/Pixelart-tv-iso.png"
        anchors.centerIn: parent
    }
}

I want to scale the art, so I increase the size:

import QtQuick 2.2
import QtQuick.Controls 1.1

ApplicationWindow {
    id: window
    visible: true
    width: 300
    height: 300
    title: qsTr("PixelArt")

    Image {
        source: "http://upload.wikimedia.org/wikipedia/commons/f/f0/Pixelart-tv-iso.png"
        anchors.centerIn: parent
        width: 256
        height: 256
    }
}

The image becomes blurry. How can I scale the image while preserving its "sharpness", so that it looks like this:


回答1:


The image is blurry when scaled because the smooth property is true by default.

Primarily used in image based items to decide if the item should use smooth sampling or not. Smooth sampling is performed using linear interpolation, while non-smooth is performed using nearest neighbor.

Set it to false to stop this from happening:

import QtQuick 2.2
import QtQuick.Controls 1.1

ApplicationWindow {
    id: window
    visible: true
    width: 300
    height: 300
    title: qsTr("PixelArt")

    Image {
        source: "http://upload.wikimedia.org/wikipedia/commons/f/f0/Pixelart-tv-iso.png"
        anchors.centerIn: parent
        width: 256
        height: 256
        smooth: false
    }
}

For more information on scaling, see:

http://en.wikipedia.org/wiki/Image_scaling



来源:https://stackoverflow.com/questions/23579857/scaling-pixel-art-with-qt-quick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!