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