ドット絵ツールを作りたい。
成果物

コード
main.py
#!/usr/bin/python # -*- coding: utf-8 -*- import sys, os from PySide2.QtWidgets import* from PySide2.QtGui import* from PySide2 import QtCore import PySide2 def get_img_path(): here = os.path.dirname(os.path.abspath(__file__)) parent = os.path.dirname(here) return os.path.join(parent, 'res', 'img.png') application = QApplication(sys.argv) window = QWidget() window.setWindowTitle("QPixmap") picture = QPixmap(get_img_path()) picture = picture.scaledToHeight(picture.height() * 12, QtCore.Qt.FastTransformation) label = QLabel(window) label.setPixmap(picture) label.setGeometry(QtCore.QRect(0, 0, picture.width(), picture.height())) window.resize(picture.width(), picture.height()) window.show() sys.exit(application.exec_())
python3 main.py

所感
ニアレストネイバーで拡大できた。
あとは以下のようなことを再現できればドット絵エディタが作れそう。
- グリッド描画
- マウス、キー入力
- 鉛筆ツール
- gif, pngなどへ書き出し
情報源
- https://qiita.com/kanryu/items/89812b362dfd581a4c10
- https://doc.qt.io/qt-5/qpixmap.html
- https://doc.qt.io/qtforpython/PySide2/QtWidgets/QGraphicsView.html
- https://doc.qt.io/qt-5/qtwidgets-widgets-imageviewer-example.html
対象環境
- Raspbierry pi 4 Model B
- Raspbian buster 10.0 2019-09-26 ※
- bash 5.0.3(1)-release
- Python 3.7.3
- Qt 5.11
- PySide
$ uname -a Linux raspberrypi 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l GNU/Linux