QImageWriterclass provides a format independent interface for writing images to files or other devices. 更多 …
def
canWrite
()
def
压缩
()
def
description
()
def
device
()
def
error
()
def
errorString
()
def
fileName
()
def
format
()
def
gamma
()
def
optimizedWrite
()
def
progressiveScanWrite
()
def
quality
()
def
setCompression
(compression)
def
setDescription
(description)
def
setDevice
(device)
def
setFileName
(fileName)
def
setFormat
(format)
def
setGamma
(gamma)
def
setOptimizedWrite
(optimize)
def
setProgressiveScanWrite
(progressive)
def
setQuality
(quality)
def
setSubType
(type)
def
setText
(key, text)
def
setTransformation
(orientation)
def
subType
()
def
supportedSubTypes
()
def
supportsOption
(option)
def
transformation
()
def
write
(image)
def
imageFormatsForMimeType
(mimeType)
def
supportedImageFormats
()
def
supportedMimeTypes
()
QImageWritersupports setting format specific options, such as compression level and quality, prior to storing the image. If you do not need such options, you can usesave()orsave()代替。To store an image, you start by constructing a
QImageWriterobject. Pass either a file name or a device pointer, and the image format toQImageWriter‘s constructor. You can then set several options, such as quality (by callingsetQuality()).canWrite()返回trueifQImageWritercan write the image (i.e., the image format is supported and the device is open for writing). Callwrite()to write the image to the device.If any error occurs when writing the image,
write()will return false. You can then callerror()to find the type of error that occurred, orerrorString()to get a human readable description of what went wrong.调用
supportedImageFormats()for a list of formats thatQImageWritercan write.QImageWritersupports all built-in image formats, in addition to any image format plugins that support writing.注意
QImageWriterassumes exclusive control over the file or device that is assigned. Any attempts to modify the assigned file or device during the lifetime of theQImageWriterobject will yield undefined results. If immediate access to a resource is desired, the use of a scope is the recommended method.例如:
QString imagePath(QStringLiteral("path/image.jpeg")); QImage image(64, 64, QImage::Format_RGB32); image.fill(Qt::red); { QImageWriter writer(imagePath); writer.write(image); } QFile::rename(imagePath, QStringLiteral("path/other_image.jpeg"));另请参阅
QImageReaderQImageIOHandlerQImageIOPluginQColorSpace
QImageWriter
¶
QImageWriter(device, format)
QImageWriter(fileName[, format=QByteArray()])
- param format
QByteArray- param device
QIODevice- param fileName
unicode
构造空
QImageWriter
object. Before writing, you must call
setFormat()
to set an image format, then
setDevice()
or
setFileName()
.
PySide2.QtGui.QImageWriter.
ImageWriterError
¶
This enum describes errors that can occur when writing images with
QImageWriter
.
|
常量 |
描述 |
|---|---|
|
QImageWriter.DeviceError |
|
|
QImageWriter.UnsupportedFormatError |
Qt 不支持请求的图像格式。 |
|
QImageWriter.InvalidImageError |
An attempt was made to write an invalid
|
|
QImageWriter.UnknownError |
An unknown error occurred. If you get this value after calling
|
PySide2.QtGui.QImageWriter.
canWrite
(
)
¶
bool
返回
true
if
QImageWriter
can write the image; i.e., the image format is supported and the assigned device is open for reading.
PySide2.QtGui.QImageWriter.
压缩
(
)
¶
int
Returns the compression of the image.
另请参阅
PySide2.QtGui.QImageWriter.
description
(
)
¶
unicode
注意
此函数被弃用。
使用
text()
代替。
Returns the description of the image.
另请参阅
PySide2.QtGui.QImageWriter.
device
(
)
¶
QIODevice
Returns the device currently assigned to
QImageWriter
,或
None
若没有设备被赋值。
另请参阅
PySide2.QtGui.QImageWriter.
error
(
)
¶
返回最后发生的错误类型。
另请参阅
ImageWriterError
errorString()
PySide2.QtGui.QImageWriter.
fileName
(
)
¶
unicode
若目前赋值设备是
QFile
,或者若
setFileName()
has been called, this function returns the name of the file
QImageWriter
writes to. Otherwise (i.e., if no device has been assigned or the device is not a
QFile
), an empty
QString
被返回。
另请参阅
PySide2.QtGui.QImageWriter.
format
(
)
¶
QByteArray
返回格式
QImageWriter
uses for writing images.
另请参阅
PySide2.QtGui.QImageWriter.
gamma
(
)
¶
float
注意
此函数被弃用。
使用
colorSpace()
and
gamma()
代替。
Returns the gamma level of the image.
另请参阅
PySide2.QtGui.QImageWriter.
imageFormatsForMimeType
(
mimeType
)
¶
mimeType
–
QByteArray
Returns the list of image formats corresponding to
mimeType
.
注意:
QGuiApplication
实例必须被创建在调用此函数之前。
PySide2.QtGui.QImageWriter.
optimizedWrite
(
)
¶
bool
Returns whether optimization has been turned on for writing the image.
另请参阅
PySide2.QtGui.QImageWriter.
progressiveScanWrite
(
)
¶
bool
Returns whether the image should be written as a progressive image.
PySide2.QtGui.QImageWriter.
quality
(
)
¶
int
返回图像格式的品质设置。
另请参阅
PySide2.QtGui.QImageWriter.
setCompression
(
压缩
)
¶
压缩
–
int
This is an image format specific function that set the compression of an image. For image formats that do not support setting the compression, this value is ignored.
The value range of
压缩
depends on the image format. For example, the “tiff” format supports two values, 0(no compression) and 1(LZW-compression).
另请参阅
PySide2.QtGui.QImageWriter.
setDescription
(
description
)
¶
description – unicode
注意
此函数被弃用。
使用
setText()
代替。
This is an image format specific function that sets the description of the image to
description
. For image formats that do not support setting the description, this value is ignored.
The contents of
description
depends on the image format.
另请参阅
PySide2.QtGui.QImageWriter.
setDevice
(
device
)
¶
device
–
QIODevice
集
QImageWriter
‘s device to
device
. If a device has already been set, the old device is removed from
QImageWriter
and is otherwise left unchanged.
若设备尚未打开,
QImageWriter
will attempt to open the device in
WriteOnly
mode by calling open(). Note that this does not work for certain devices, such as
QProcess
,
QTcpSocket
and
QUdpSocket
, where more logic is required to open the device.
另请参阅
PySide2.QtGui.QImageWriter.
setFileName
(
fileName
)
¶
fileName – unicode
Sets the file name of
QImageWriter
to
fileName
. Internally,
QImageWriter
will create a
QFile
and open it in
WriteOnly
mode, and use this file when writing images.
另请参阅
PySide2.QtGui.QImageWriter.
setFormat
(
format
)
¶
format
–
QByteArray
设置格式
QImageWriter
will use when writing images, to
format
.
format
is a case insensitive text string. Example:
writer = QImageWriter()
writer.setFormat("png") # same as writer.setFormat("PNG")
可以调用
supportedImageFormats()
for the full list of formats
QImageWriter
支持。
另请参阅
PySide2.QtGui.QImageWriter.
setGamma
(
gamma
)
¶
gamma
–
float
注意
此函数被弃用。
使用
QColorSpace
conversion on the
QImage
代替。
This is an image format specific function that sets the gamma level of the image to
gamma
. For image formats that do not support setting the gamma level, this value is ignored.
The value range of
gamma
depends on the image format. For example, the “png” format supports a gamma range from 0.0 to 1.0.
PySide2.QtGui.QImageWriter.
setOptimizedWrite
(
optimize
)
¶
optimize
–
bool
This is an image format-specific function which sets the
optimize
flags when writing images. For image formats that do not support setting an
optimize
flag, this value is ignored.
默认为 false。
另请参阅
PySide2.QtGui.QImageWriter.
setProgressiveScanWrite
(
progressive
)
¶
progressive
–
bool
This is an image format-specific function which turns on
progressive
scanning when writing images. For image formats that do not support setting a
progressive
scan flag, this value is ignored.
默认为 false。
PySide2.QtGui.QImageWriter.
setQuality
(
quality
)
¶
quality
–
int
将图像格式的品质设置设为
quality
.
Some image formats, in particular lossy ones, entail a tradeoff between a) visual quality of the resulting image, and b) encoding execution time and compression level. This function sets the level of that tradeoff for image formats that support it. For other formats, this value is ignored.
The value range of
quality
depends on the image format. For example, the “jpeg” format supports a quality range from 0 (low visual quality, high compression) to 100 (high visual quality, low compression).
另请参阅
PySide2.QtGui.QImageWriter.
setSubType
(
type
)
¶
type
–
QByteArray
This is an image format specific function that sets the subtype of the image to
type
. Subtype can be used by a handler to determine which format it should use while saving the image.
For example, saving an image in DDS format with A8R8G8R8 subtype:
QImageWriter writer("some/image.dds");
if (writer.supportsOption(QImageIOHandler::SubType))
writer.setSubType("A8R8G8B8");
writer.write(image);
另请参阅
PySide2.QtGui.QImageWriter.
setText
(
key
,
text
)
¶
key – unicode
text – unicode
Sets the image text associated with the key
key
to
text
. This is useful for storing copyright information or other information about the image. Example:
image = QImage("some/image.jpeg")
writer = QImageWriter("images/outimage.png", "png")
writer.setText("Author", "John Smith")
writer.write(image)
If you want to store a single block of data (e.g., a comment), you can pass an empty key, or use a generic key like “Description”.
The key and text will be embedded into the image data after calling
write()
.
支持此选项的实现是透过
描述
.
PySide2.QtGui.QImageWriter.
setTransformation
(
orientation
)
¶
orientation
–
变换
Sets the image transformations metadata including orientation to
transform
.
If transformation metadata is not supported by the image format, the transform is applied before writing.
另请参阅
PySide2.QtGui.QImageWriter.
subType
(
)
¶
QByteArray
返回图像的子类型。
另请参阅
PySide2.QtGui.QImageWriter.
supportedImageFormats
(
)
¶
Returns the list of image formats supported by
QImageWriter
.
By default, Qt can write the following formats:
|
格式 |
MIME 类型 |
描述 |
|
BMP |
image/bmp |
Windows 位图 |
|
JPG |
image/jpeg |
Joint Photographic Experts Group (联合摄影专家组) |
|
PNG |
image/png |
Portable Network Graphics (便携式网络图形) |
|
PBM |
image/x-portable-bitmap |
Portable Bitmap (便携式位图) |
|
PGM |
image/x-portable-graymap |
Portable Graymap (便携式灰度图) |
|
PPM |
image/x-portable-pixmap |
Portable Pixmap (便携式像素图) |
|
XBM |
image/x-xbitmap |
X11 Bitmap (X11 位图) |
|
XPM |
image/x-xpixmap |
X11 Pixmap (X11 像素图) |
Reading and writing SVG files is supported through the Qt SVG module. The Qt Image Formats module provides support for additional image formats.
注意:
QApplication
实例必须被创建在调用此函数之前。
另请参阅
setFormat()
supportedImageFormats()
QImageIOPlugin
PySide2.QtGui.QImageWriter.
supportedMimeTypes
(
)
¶
Returns the list of MIME types supported by
QImageWriter
.
注意:
QApplication
实例必须被创建在调用此函数之前。
PySide2.QtGui.QImageWriter.
supportedSubTypes
(
)
¶
返回由图像所支持的子类型列表。
PySide2.QtGui.QImageWriter.
supportsOption
(
option
)
¶
option
–
ImageOption
bool
返回
true
if the writer supports
option
;否则返回 false。
Different image formats support different options. Call this function to determine whether a certain option is supported by the current format. For example, the PNG format allows you to embed text into the image’s metadata (see text()).
writer = QImageWriter(fileName)
if writer.supportsOption(QImageIOHandler.Description):
writer.setText("Author", "John Smith")
Options can be tested after the writer has been associated with a format.
PySide2.QtGui.QImageWriter.
transformation
(
)
¶
变换
Returns the transformation and orientation the image has been set to written with.
另请参阅
PySide2.QtGui.QImageWriter.
write
(
image
)
¶
image
–
QImage
bool
写入图像
image
to the assigned device or file name. Returns
true
当成功时;否则返回
false
. If the operation fails, you can call
error()
to find the type of error that occurred, or
errorString()
to get a human readable description of the error.