Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qimagewriter.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4/*!
5 \class QImageWriter
6 \brief The QImageWriter class provides a format independent interface
7 for writing images to files or other devices.
8
9 \inmodule QtGui
10 \reentrant
11 \ingroup painting
12
13 QImageWriter supports setting format specific options, such as
14 compression level and quality, prior to storing the
15 image. If you do not need such options, you can use QImage::save()
16 or QPixmap::save() instead.
17
18 To store an image, you start by constructing a QImageWriter
19 object. Pass either a file name or a device pointer, and the
20 image format to QImageWriter's constructor. You can then set
21 several options, such as quality (by calling setQuality()).
22 canWrite() returns \c true if QImageWriter can write the image
23 (i.e., the image format is supported and the device is open for
24 writing). Call write() to write the image to the device.
25
26 If any error occurs when writing the image, write() will return
27 false. You can then call error() to find the type of error that
28 occurred, or errorString() to get a human readable description of
29 what went wrong.
30
31 Call supportedImageFormats() for a list of formats that
32 QImageWriter can write. QImageWriter supports all built-in image
33 formats, in addition to any image format plugins that support
34 writing.
35
36 \note QImageWriter assumes exclusive control over the file or
37 device that is assigned. Any attempts to modify the assigned file
38 or device during the lifetime of the QImageWriter object will
39 yield undefined results. If immediate access to a resource is
40 desired, the use of a scope is the recommended method.
41
42 For example:
43
44 \snippet qimagewriter/main.cpp 0
45
46 \sa QImageReader, QImageIOHandler, QImageIOPlugin, QColorSpace
47*/
48
49/*!
50 \enum QImageWriter::ImageWriterError
51
52 This enum describes errors that can occur when writing images with
53 QImageWriter.
54
55 \value DeviceError QImageWriter encountered a device error when
56 writing the image data. Consult your device for more details on
57 what went wrong.
58
59 \value UnsupportedFormatError Qt does not support the requested
60 image format.
61
62 \value InvalidImageError An attempt was made to write an invalid QImage. An
63 example of an invalid image would be a null QImage.
64
65 \value UnknownError An unknown error occurred. If you get this
66 value after calling write(), it is most likely caused by a bug in
67 QImageWriter.
68*/
69// Qt-Security score:significant reason:default
70
71#include "qimagewriter.h"
72
73#include <qbytearray.h>
74#include <qfile.h>
75#include <qfileinfo.h>
76#include <qimage.h>
77#include <qimageiohandler.h>
78#include <qset.h>
79#include <qvariant.h>
80#include <qloggingcategory.h>
81
82// factory loader
83#include <qcoreapplication.h>
84#include <private/qfactoryloader_p.h>
85
86// image handlers
87#include <private/qbmphandler_p.h>
88#include <private/qppmhandler_p.h>
89#include <private/qxbmhandler_p.h>
90#include <private/qxpmhandler_p.h>
91#ifndef QT_NO_IMAGEFORMAT_PNG
92#include <private/qpnghandler_p.h>
93#endif
94
95#include <private/qimagereaderwriterhelpers_p.h>
96
97#include <algorithm>
98
99QT_BEGIN_NAMESPACE
100
101Q_STATIC_LOGGING_CATEGORY(lcImageWriter, "qt.gui.imageio.writer")
102
103using namespace Qt::StringLiterals;
104
106 const QByteArray &format)
107{
108 QByteArray form = format.toLower();
109 QByteArray suffix;
110 QImageIOHandler *handler = nullptr;
111
112 qCDebug(lcImageWriter) << "Finding write handler for" << device << "and format" << format;
113
114#ifndef QT_NO_IMAGEFORMATPLUGIN
115 typedef QMultiMap<int, QString> PluginKeyMap;
116
117 // check if any plugins can write the image
118 auto l = QImageReaderWriterHelpers::pluginLoader();
119 const PluginKeyMap keyMap = l->keyMap();
120 int suffixPluginIndex = -1;
121
122 qCDebug(lcImageWriter) << keyMap.uniqueKeys().size() << "plugins available:" << keyMap.values();
123#endif
124
125 if (device && format.isEmpty()) {
126 // if there's no format, see if \a device is a file, and if so, find
127 // the file suffix and find support for that format among our plugins.
128 // this allows plugins to override our built-in handlers.
129 if (QFileDevice *file = qobject_cast<QFileDevice *>(device)) {
130 if (!(suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1()).isEmpty()) {
131 qCDebug(lcImageWriter) << "Resolved format" << suffix << "from file name suffix";
132#ifndef QT_NO_IMAGEFORMATPLUGIN
133 const int index = keyMap.key(QString::fromLatin1(suffix), -1);
134 if (index != -1)
135 suffixPluginIndex = index;
136#endif
137 }
138 }
139 }
140
141 QByteArray testFormat = !form.isEmpty() ? form : suffix;
142
143#ifndef QT_NO_IMAGEFORMATPLUGIN
144 if (suffixPluginIndex != -1) {
145 // when format is missing, check if we can find a plugin for the
146 // suffix.
147 qCDebug(lcImageWriter) << "Checking if any plugins have explicitly declared support"
148 << "for the format" << testFormat;
149 const int index = keyMap.key(QString::fromLatin1(suffix), -1);
150 if (index != -1) {
151 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(index));
152 if (plugin && (plugin->capabilities(device, suffix) & QImageIOPlugin::CanWrite)) {
153 handler = plugin->create(device, suffix);
154 qCDebug(lcImageWriter) << plugin << "can write the format" << testFormat;
155 }
156 }
157 }
158#endif // QT_NO_IMAGEFORMATPLUGIN
159
160 // check if any built-in handlers can write the image
161 if (!handler && !testFormat.isEmpty()) {
162 qCDebug(lcImageWriter) << "Checking if any built in handlers recognize the format"
163 << testFormat;
164 if (false) {
165#ifndef QT_NO_IMAGEFORMAT_PNG
166 } else if (testFormat == "png") {
167 handler = new QPngHandler;
168#endif
169#ifndef QT_NO_IMAGEFORMAT_BMP
170 } else if (testFormat == "bmp") {
171 handler = new QBmpHandler;
172 } else if (testFormat == "dib") {
173 handler = new QBmpHandler(QBmpHandler::DibFormat);
174#endif
175#ifndef QT_NO_IMAGEFORMAT_XPM
176 } else if (testFormat == "xpm") {
177 handler = new QXpmHandler;
178#endif
179#ifndef QT_NO_IMAGEFORMAT_XBM
180 } else if (testFormat == "xbm") {
181 handler = new QXbmHandler;
182 handler->setOption(QImageIOHandler::SubType, testFormat);
183#endif
184#ifndef QT_NO_IMAGEFORMAT_PPM
185 } else if (testFormat == "pbm" || testFormat == "pbmraw" || testFormat == "pgm"
186 || testFormat == "pgmraw" || testFormat == "ppm" || testFormat == "ppmraw") {
187 handler = new QPpmHandler;
188 handler->setOption(QImageIOHandler::SubType, testFormat);
189#endif
190 }
191
192 if (handler)
193 qCDebug(lcImageWriter) << "Using the built-in handler for format" << testFormat;
194 }
195
196#ifndef QT_NO_IMAGEFORMATPLUGIN
197 if (!handler && !testFormat.isEmpty()) {
198 qCDebug(lcImageWriter) << "Checking if any plugins recognize the format" << testFormat;
199 const int keyCount = keyMap.size();
200 for (int i = 0; i < keyCount; ++i) {
201 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(i));
202 if (plugin && (plugin->capabilities(device, testFormat) & QImageIOPlugin::CanWrite)) {
203 handler = plugin->create(device, testFormat);
204 qCDebug(lcImageWriter) << plugin << "can write the format" << testFormat;
205 break;
206 }
207 }
208 }
209#endif // QT_NO_IMAGEFORMATPLUGIN
210
211 if (!handler) {
212 qCDebug(lcImageWriter, "No handlers found. Giving up.");
213 return nullptr;
214 }
215
216 handler->setDevice(device);
217 if (!testFormat.isEmpty())
218 handler->setFormat(testFormat);
219 return handler;
220}
221
252
253/*!
254 \internal
255*/
257{
258 device = nullptr;
259 deleteDevice = false;
260 handler = nullptr;
261 quality = -1;
262 compression = -1;
263 gamma = 0.0;
264 optimizedWrite = false;
265 progressiveScanWrite = false;
266 imageWriterError = QImageWriter::UnknownError;
267 errorString = QImageWriter::tr("Unknown error");
268 transformation = QImageIOHandler::TransformationNone;
269
270 q = qq;
271}
272
274{
275 if (!device) {
276 imageWriterError = QImageWriter::DeviceError;
277 errorString = QImageWriter::tr("Device is not set");
278 return false;
279 }
280 if (!device->isOpen()) {
281 if (!device->open(QIODevice::WriteOnly)) {
282 imageWriterError = QImageWriter::DeviceError;
283 errorString = QImageWriter::tr("Cannot open device for writing: %1").arg(device->errorString());
284 return false;
285 }
286 }
287 if (!device->isWritable()) {
288 imageWriterError = QImageWriter::DeviceError;
289 errorString = QImageWriter::tr("Device not writable");
290 return false;
291 }
292 if (!handler && (handler = createWriteHandlerHelper(device, format)) == nullptr) {
293 imageWriterError = QImageWriter::UnsupportedFormatError;
294 errorString = QImageWriter::tr("Unsupported image format");
295 return false;
296 }
297 return true;
298}
299
300/*!
301 Constructs an empty QImageWriter object. Before writing, you must
302 call setFormat() to set an image format, then setDevice() or
303 setFileName().
304*/
305QImageWriter::QImageWriter()
306 : d(new QImageWriterPrivate(this))
307{
308}
309
310/*!
311 Constructs a QImageWriter object using the device \a device and
312 image format \a format.
313*/
314QImageWriter::QImageWriter(QIODevice *device, const QByteArray &format)
315 : d(new QImageWriterPrivate(this))
316{
317 d->device = device;
318 d->format = format;
319}
320
321/*!
322 Constructs a QImageWriter objects that will write to a file with
323 the name \a fileName, using the image format \a format. If \a
324 format is not provided, QImageWriter will detect the image format
325 by inspecting the extension of \a fileName.
326*/
327QImageWriter::QImageWriter(const QString &fileName, const QByteArray &format)
328 : QImageWriter(new QFile(fileName), format)
329{
330 d->deleteDevice = true;
331}
332
333/*!
334 Destructs the QImageWriter object.
335*/
336QImageWriter::~QImageWriter()
337{
338 delete d->handler;
339 if (d->deleteDevice)
340 delete d->device;
341 delete d;
342}
343
344/*!
345 Sets the format QImageWriter will use when writing images, to \a
346 format. \a format is a case insensitive text string. Example:
347
348 \snippet code/src_gui_image_qimagewriter.cpp 0
349
350 You can call supportedImageFormats() for the full list of formats
351 QImageWriter supports.
352
353 \sa format()
354*/
355void QImageWriter::setFormat(const QByteArray &format)
356{
357 d->format = format;
358}
359
360/*!
361 Returns the format QImageWriter uses for writing images.
362
363 \sa setFormat()
364*/
365QByteArray QImageWriter::format() const
366{
367 return d->format;
368}
369
370/*!
371 Sets QImageWriter's device to \a device. If a device has already
372 been set, the old device is removed from QImageWriter and is
373 otherwise left unchanged.
374
375 If the device is not already open, QImageWriter will attempt to
376 open the device in \l QIODeviceBase::WriteOnly mode by calling
377 open(). Note that this does not work for certain devices, such as
378 QProcess, QTcpSocket and QUdpSocket, where more logic is required
379 to open the device.
380
381 \sa device(), setFileName()
382*/
383void QImageWriter::setDevice(QIODevice *device)
384{
385 delete d->handler;
386 d->handler = nullptr;
387 if (d->device && d->deleteDevice)
388 delete d->device;
389
390 d->device = device;
391 d->deleteDevice = false;
392}
393
394/*!
395 Returns the device currently assigned to QImageWriter, or \nullptr
396 if no device has been assigned.
397*/
398QIODevice *QImageWriter::device() const
399{
400 return d->device;
401}
402
403/*!
404 Sets the file name of QImageWriter to \a fileName. Internally,
405 QImageWriter will create a QFile and open it in \l
406 QIODevice::WriteOnly mode, and use this file when writing images.
407
408 \sa fileName(), setDevice()
409*/
410void QImageWriter::setFileName(const QString &fileName)
411{
412 setDevice(new QFile(fileName));
413 d->deleteDevice = true;
414}
415
416/*!
417 If the currently assigned device is a file, or if setFileName()
418 has been called, this function returns the name of the file
419 QImageWriter writes to. Otherwise (i.e., if no device has been
420 assigned or the device is not a file), an empty QString is
421 returned.
422
423 \sa setFileName(), setDevice()
424*/
425QString QImageWriter::fileName() const
426{
427 QFileDevice *file = qobject_cast<QFileDevice *>(d->device);
428 return file ? file->fileName() : QString();
429}
430
431/*!
432 Sets the quality setting of the image format to \a quality.
433
434 Some image formats, in particular lossy ones, entail a tradeoff between a)
435 visual quality of the resulting image, and b) encoding execution time and
436 compression level. This function sets the level of that tradeoff for image
437 formats that support it. For other formats, this value is ignored.
438
439 The value range of \a quality depends on the image format. For example,
440 the "jpeg" format supports a quality range from 0 (low visual quality, high
441 compression) to 100 (high visual quality, low compression).
442
443 \sa quality()
444*/
445void QImageWriter::setQuality(int quality)
446{
447 d->quality = quality;
448}
449
450/*!
451 Returns the quality setting of the image format.
452
453 \sa setQuality()
454*/
455int QImageWriter::quality() const
456{
457 return d->quality;
458}
459
460/*!
461 This is an image format specific function that set the compression
462 of an image. For image formats that do not support setting the
463 compression, this value is ignored.
464
465 The value range of \a compression depends on the image format:
466 \table
467 \header
468 \li Image Format
469 \li Supported Values
470 \row
471 \li PNG
472 \li Values in the range from 0 (no compression) to 100 (low visual
473 quality, maximum compression). This value is the inverse to
474 \e quality in setQuality. The two options are mutually exclusive.
475 \row
476 \li TGA
477 \li
478 0 - No compression \br
479 1 - RLE compression
480 \row
481 \li TIFF
482 \li
483 0 - No compression \br
484 1 - LZW compression \br
485 2 - RLE compression \br
486 3 - CCITT Group 3 fax encoding \br
487 4 - CCITT Group 4 fax encoding \br
488 5 - JPEG compression
489 \endtable
490
491 \sa compression(), setQuality()
492*/
493void QImageWriter::setCompression(int compression)
494{
495 d->compression = compression;
496}
497
498/*!
499 Returns the compression of the image.
500
501 \sa setCompression()
502*/
503int QImageWriter::compression() const
504{
505 return d->compression;
506}
507
508/*!
509 \since 5.4
510
511 This is an image format specific function that sets the
512 subtype of the image to \a type. Subtype can be used by
513 a handler to determine which format it should use while
514 saving the image.
515
516 For example, saving an image in DDS format with A8R8G8R8 subtype:
517
518 \snippet code/src_gui_image_qimagewriter.cpp 3
519*/
520void QImageWriter::setSubType(const QByteArray &type)
521{
522 d->subType = type;
523}
524
525/*!
526 \since 5.4
527
528 Returns the subtype of the image.
529
530 \sa setSubType()
531*/
532QByteArray QImageWriter::subType() const
533{
534 return d->subType;
535}
536
537/*!
538 \since 5.4
539
540 Returns the list of subtypes supported by an image.
541*/
542QList<QByteArray> QImageWriter::supportedSubTypes() const
543{
544 if (!supportsOption(QImageIOHandler::SupportedSubTypes))
545 return QList<QByteArray>();
546 return qvariant_cast<QList<QByteArray> >(d->handler->option(QImageIOHandler::SupportedSubTypes));
547}
548
549/*!
550 \since 5.5
551
552 This is an image format-specific function which sets the \a optimize flags when
553 writing images. For image formats that do not support setting an \a optimize flag,
554 this value is ignored.
555
556 The default is false.
557
558 \sa optimizedWrite()
559*/
560void QImageWriter::setOptimizedWrite(bool optimize)
561{
562 d->optimizedWrite = optimize;
563}
564
565/*!
566 \since 5.5
567
568 Returns whether optimization has been turned on for writing the image.
569
570 \sa setOptimizedWrite()
571*/
572bool QImageWriter::optimizedWrite() const
573{
574 return d->optimizedWrite;
575}
576
577/*!
578 \since 5.5
579
580 This is an image format-specific function which turns on \a progressive scanning
581 when writing images. For image formats that do not support setting a \a progressive
582 scan flag, this value is ignored.
583
584 The default is false.
585
586 \sa progressiveScanWrite()
587*/
588
589void QImageWriter::setProgressiveScanWrite(bool progressive)
590{
591 d->progressiveScanWrite = progressive;
592}
593
594/*!
595 \since 5.5
596
597 Returns whether the image should be written as a progressive image.
598
599 \sa setProgressiveScanWrite()
600*/
601bool QImageWriter::progressiveScanWrite() const
602{
603 return d->progressiveScanWrite;
604}
605
606/*!
607 \since 5.5
608
609 Sets the image transformations metadata including orientation to \a transform.
610
611 If transformation metadata is not supported by the image format,
612 the transform is applied before writing.
613
614 \sa transformation(), write()
615*/
616void QImageWriter::setTransformation(QImageIOHandler::Transformations transform)
617{
618 d->transformation = transform;
619}
620
621/*!
622 \since 5.5
623
624 Returns the transformation and orientation the image has been set to written with.
625
626 \sa setTransformation()
627*/
628QImageIOHandler::Transformations QImageWriter::transformation() const
629{
630 return d->transformation;
631}
632
633/*!
634 Sets the image text associated with the key \a key to
635 \a text. This is useful for storing copyright information
636 or other information about the image. Example:
637
638 \snippet code/src_gui_image_qimagewriter.cpp 1
639
640 If you want to store a single block of data
641 (e.g., a comment), you can pass an empty key, or use
642 a generic key like "Description".
643
644 The key and text will be embedded into the
645 image data after calling write().
646
647 Support for this option is implemented through
648 QImageIOHandler::Description.
649
650 \sa QImage::setText(), QImageReader::text()
651*/
652void QImageWriter::setText(const QString &key, const QString &text)
653{
654 if (!d->description.isEmpty())
655 d->description += "\n\n"_L1;
656 d->description += key.simplified() + ": "_L1 + text.simplified();
657}
658
659/*!
660 Returns \c true if QImageWriter can write the image; i.e., the image
661 format is supported and the assigned device is open for reading.
662
663 \sa write(), setDevice(), setFormat()
664*/
665bool QImageWriter::canWrite() const
666{
667 if (QFile *file = qobject_cast<QFile *>(d->device)) {
668 const bool remove = !file->isOpen() && !file->exists();
669 const bool result = d->canWriteHelper();
670
671 // This looks strange (why remove if it doesn't exist?) but the issue
672 // here is that canWriteHelper will create the file in the process of
673 // checking if the write can succeed. If it subsequently fails, we
674 // should remove that empty file.
675 if (!result && remove)
676 file->remove();
677 return result;
678 }
679
680 return d->canWriteHelper();
681}
682
683extern void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient);
684
685/*!
686 Writes the image \a image to the assigned device or file
687 name. Returns \c true on success; otherwise returns \c false. If the
688 operation fails, you can call error() to find the type of error
689 that occurred, or errorString() to get a human readable
690 description of the error.
691
692 \sa canWrite(), error(), errorString()
693*/
694bool QImageWriter::write(const QImage &image)
695{
696 // Do this before canWrite, so it doesn't create a file if this fails.
697 if (Q_UNLIKELY(image.isNull())) {
698 d->imageWriterError = QImageWriter::InvalidImageError;
699 d->errorString = QImageWriter::tr("Image is empty");
700 return false;
701 }
702
703 if (!canWrite())
704 return false;
705
706 QImage img = image;
707 if (d->handler->supportsOption(QImageIOHandler::Quality))
708 d->handler->setOption(QImageIOHandler::Quality, d->quality);
709 if (d->handler->supportsOption(QImageIOHandler::CompressionRatio))
710 d->handler->setOption(QImageIOHandler::CompressionRatio, d->compression);
711 if (d->handler->supportsOption(QImageIOHandler::Gamma))
712 d->handler->setOption(QImageIOHandler::Gamma, d->gamma);
713 if (!d->description.isEmpty() && d->handler->supportsOption(QImageIOHandler::Description))
714 d->handler->setOption(QImageIOHandler::Description, d->description);
715 if (!d->subType.isEmpty() && d->handler->supportsOption(QImageIOHandler::SubType))
716 d->handler->setOption(QImageIOHandler::SubType, d->subType);
717 if (d->handler->supportsOption(QImageIOHandler::OptimizedWrite))
718 d->handler->setOption(QImageIOHandler::OptimizedWrite, d->optimizedWrite);
719 if (d->handler->supportsOption(QImageIOHandler::ProgressiveScanWrite))
720 d->handler->setOption(QImageIOHandler::ProgressiveScanWrite, d->progressiveScanWrite);
721 if (d->handler->supportsOption(QImageIOHandler::ImageTransformation))
722 d->handler->setOption(QImageIOHandler::ImageTransformation, int(d->transformation));
723 else
724 qt_imageTransform(img, d->transformation);
725
726 if (!d->handler->write(img))
727 return false;
728 if (QFileDevice *file = qobject_cast<QFileDevice *>(d->device))
729 file->flush();
730 return true;
731}
732
733/*!
734 Returns the type of error that last occurred.
735
736 \sa ImageWriterError, errorString()
737*/
738QImageWriter::ImageWriterError QImageWriter::error() const
739{
740 return d->imageWriterError;
741}
742
743/*!
744 Returns a human readable description of the last error that occurred.
745
746 \sa error()
747*/
748QString QImageWriter::errorString() const
749{
750 return d->errorString;
751}
752
753/*!
754 Returns \c true if the writer supports \a option; otherwise returns
755 false.
756
757 Different image formats support different options. Call this function to
758 determine whether a certain option is supported by the current format. For
759 example, the PNG format allows you to embed text into the image's metadata
760 (see text()).
761
762 \snippet code/src_gui_image_qimagewriter.cpp 2
763
764 Options can be tested after the writer has been associated with a format.
765
766 \sa QImageReader::supportsOption(), setFormat()
767*/
768bool QImageWriter::supportsOption(QImageIOHandler::ImageOption option) const
769{
770 if (!d->handler && (d->handler = createWriteHandlerHelper(d->device, d->format)) == nullptr) {
771 d->imageWriterError = QImageWriter::UnsupportedFormatError;
772 d->errorString = QImageWriter::tr("Unsupported image format");
773 return false;
774 }
775
776 return d->handler->supportsOption(option);
777}
778
779/*!
780 Returns the list of image formats supported by QImageWriter.
781
782 By default, Qt can write the following formats:
783
784 \table
785 \header \li Format \li MIME type \li Description
786 \row \li BMP \li image/bmp \li Windows Bitmap
787 \row \li JPG \li image/jpeg \li Joint Photographic Experts Group
788 \row \li PNG \li image/png \li Portable Network Graphics
789 \row \li PBM \li image/x-portable-bitmap \li Portable Bitmap
790 \row \li PGM \li image/x-portable-graymap \li Portable Graymap
791 \row \li PPM \li image/x-portable-pixmap \li Portable Pixmap
792 \row \li XBM \li image/x-xbitmap \li X11 Bitmap
793 \row \li XPM \li image/x-xpixmap \li X11 Pixmap
794 \endtable
795
796 Reading and writing SVG files is supported through the \l{Qt SVG} module.
797 The \l{Qt Image Formats} module provides support for additional image formats.
798
799 Note that the QApplication instance must be created before this function is
800 called.
801
802 \sa setFormat(), QImageReader::supportedImageFormats(), QImageIOPlugin
803*/
804QList<QByteArray> QImageWriter::supportedImageFormats()
805{
806 return QImageReaderWriterHelpers::supportedImageFormats(QImageReaderWriterHelpers::CanWrite);
807}
808
809/*!
810 Returns the list of MIME types supported by QImageWriter.
811
812 Note that the QApplication instance must be created before this function is
813 called.
814
815 \sa supportedImageFormats(), QImageReader::supportedMimeTypes()
816*/
817QList<QByteArray> QImageWriter::supportedMimeTypes()
818{
819 return QImageReaderWriterHelpers::supportedMimeTypes(QImageReaderWriterHelpers::CanWrite);
820}
821
822/*!
823 \since 5.12
824
825 Returns the list of image formats corresponding to \a mimeType.
826
827 Note that the QGuiApplication instance must be created before this function is
828 called.
829
830 \sa supportedImageFormats(), supportedMimeTypes()
831*/
832
833QList<QByteArray> QImageWriter::imageFormatsForMimeType(const QByteArray &mimeType)
834{
835 return QImageReaderWriterHelpers::imageFormatsForMimeType(mimeType,
836 QImageReaderWriterHelpers::CanWrite);
837}
838
839QT_END_NAMESPACE
QImageWriterPrivate(QImageWriter *qq)
QImageIOHandler * handler
Definition qcompare.h:111
Q_GUI_EXPORT void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient)
Definition qimage.cpp:6522
static QImageIOHandler * createWriteHandlerHelper(QIODevice *device, const QByteArray &format)
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)