#-*-Coding: UTF-8 -*-
# Python: 2.x
_ Author _ = 'admin'
From pyqt4.qtgui import *
From pyqt4.qt import *
From pyqt4 import qtgui, qtcore
From pyqt4.qtcore import *
Import sys
# Note: drawing devices inherit the class of qpainterdevice. Qpaintdevice is a class that can be drawn, that is,
# Qpainter can be drawn on any subclass of qpaintdevice
# Qglpixelbuffer has been deprecated in qt5
Qt4:
Qt5:
# Qglwidget and qglframebufferobject are related to OpenGL, as the name suggests.
"""
Qpixmap optimizes the display of images on the screen. qbitmap is a subclass of qpixmap.
The color depth is limited to 1. You can use the isqbitmap () function of qpixmap to determine whether this qpixmap is
Qbitmap. Qimage is specially optimized for Pixel-level access to images. Qpicture can be recorded and reproduced
Qpainter commands
----
Qpixmap inherits qpaintdevice. Therefore, you can use qpainter to draw a graph directly on it.
Qpixmap can also accept a string as the path of a file to display this file. For example, if you want
To open PNG, JPEG, and other files, you can use qpixmap. Use the qpainter: drawpixmap () function
This file can be drawn to a qlabel, qpushbutton, or other devices.
Qpixmap is specially optimized for the screen. Therefore, it is similar to the actual underlying display device.
Off. Note: The display device here is not a hardware, but a native Drawing Engine provided by the operating system. Therefore
The qpixmap display may vary with operating system platforms.
-----
Qpixmap provides static grabwidget () and grabwindow () functions to draw their own images to the target.
. At the same time, when using qpixmap, you can directly use the form of passing values without passing pointers, because qpixmap
Provides "implicit data sharing ".
-----
Qbitmap inherits from qpixmap, so it has all the features of qpixmap. The difference is that,
The color depth of qbitmap is always 1: The number of digits used to represent the color binary.
-----
For example, if we want to represent eight colors, we need to use three binary bits. Then we can say that the color depth is 3.
Therefore, the color depth is 1, that is, the color is represented by a binary digit. One single digit has only two States: 0 and 1,
Therefore, it represents two colors: black and white. Therefore, qbitmap is actually only a black-and-white image.
Data. Because qbitmap is small in color, it only occupies a small amount of storage space, so it is suitable for making cursor files and brushes.
"""
Class painterd (qwidget ):
Def _ init _ (Self ):
Super (painterd, self). _ init __()
Self. Resize (400,300)
Self. setwindowtitle ('paint ')
Def paintevent (self, e ):
Paint = qpainter (Self)
Pixmap = qpixmap (r' I/AB .png ')
Pitep = qpixmap (r 'I/AB .png ')
#Qt-logo.png has a transparent background and qt-logo-white.png has a white background. Difference between qpixmap and qbitmap to load them: the white background is
# Qbitmap disappears, while the transparent color is converted to black in qbitmap ("black", remember, Q bitmap only
# There are two colors: Black and White. Other colors are represented by the degree of density of points.
Paint. drawpixmap (10, 10, 250,125, pixmap)
Paint. drawpixmap (250,125, pitep)
White1 = qpixmap (r' I/cd.png ')
White2 = qpixmap (r' I/cd.png ')
Paint. drawpixmap (10,140,250,125, white1)
Paint. drawpixmap (270,140,250,125, white2)
Def main ():
APP = qtgui. qapplication (SYS. argv)
Ex = painterd ()
Ex. Show ()
Sys.exit(app.exe C _())
If _ name _ = '_ main __':
Main ()
# Note: qpixmap uses the rendering system of the underlying platform for plotting, and cannot provide pixel-level operations, while qimage is
# A hardware-independent drawing system is used to draw itself. Therefore, pixel-level operations are provided and
# It is sufficient to provide a consistent display form on different systems.
:
"""
Compared with qpixmap, qimage provides pixel-level operations. We use the above instructions
We can see from the intent that we declare a 3x3 pixel qimage object, and then use the setpixel () function for face filter.
Color settings. You can think of qimage as a two-dimensional array of RGB color, recording the color of each pixel.
It is worth noting that qimage: format_indexed8 cannot be used for plotting on qimage.
.
----
Qpicture is platform independent, so it can be used on a variety of devices, such as SVG, PDF, PS,
Printer or screen. Recall the qpaintdevice that we once mentioned. In fact, it can be implemented by qpainter.
The object to be drawn. Qpicture uses the system resolution and can adjust the qpainter to eliminate the explicit
Shows the difference. To record the command of qpainter, first use the qpainter: Begin () function
The qpicture instance is passed as a parameter to tell the system to start recording. After the record is completed, use qpainter: end ()
Command termination
Picture = qpicture ()
Pinter = qpainter ()
Pinter. Begin (picture) # Draw in picture
Pinter. drawellipse (10, 20, 80, 70) # elliptic
Pinter. End () # End
Picture. Save ('Drawing. PIC ') # Save
# If we want to reproduce the command, we must first use the qpicture: load () function for loading:
Picture. Load ('Drawing. PIC ') # Load
Pinter. Begin (myimage) myimage
Pinter. drawpicture (, picture) starts to draw picture at (0, 0 ).
Pinter. End ()
"""
:
You can also use qpicture: Play () to draw the image directly. This function accepts a qpainter object.
Is the paint brush.