⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qimage.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    If the image is in an indexed color format, set the color table    for the image using setColorTable().*/QImage::QImage(uchar* data, int width, int height, Format format)    : QPaintDevice(){    d = QImageData::create(data, width, height, 0, format, false);}/*!    Constructs an image with the given \a width, \a height and \a    format, that uses an existing read-only memory buffer, \a data. The \a width    and \a height must be specified in pixels, \a data must be 32-bit aligned,    and each scanline of data in the image must also be 32-bit aligned.    The buffer must remain valid throughout the life of the    QImage and all copies that have not been modified or otherwise detached from    the original buffer. The image does not delete the buffer at destruction.    If the image is in an indexed color format, set the color table    for the image using setColorTable().    Unlike the similar QImage constructor that takes a non-const data buffer,    this version will never alter the contents of the buffer.  For example,    calling QImage::bits() will return a deep copy of the image, rather than    the buffer passed to the constructor.  This allows for the efficiency of    constructing a QImage from raw data, without the possibility of the raw    data being changed.*/QImage::QImage(const uchar* data, int width, int height, Format format)    : QPaintDevice(){    d = QImageData::create(const_cast<uchar*>(data), width, height, 0, format, true);}/*!    Constructs an image with the given \a width, \a height and \a    format, that uses an existing memory buffer, \a data. The \a width    and \a height must be specified in pixels. \a bytesPerLine    specifies the number of bytes per line (stride).    The buffer must remain valid throughout the life of the    QImage. The image does not delete the buffer at destruction.    If the image is in an indexed color format, set the color table    for the image using setColorTable().*/QImage::QImage(uchar *data, int width, int height, int bytesPerLine, Format format)    :QPaintDevice(){    d = QImageData::create(data, width, height, bytesPerLine, format, false);}/*!    Constructs an image with the given \a width, \a height and \a    format, that uses an existing memory buffer, \a data. The \a width    and \a height must be specified in pixels. \a bytesPerLine    specifies the number of bytes per line (stride).    The buffer must remain valid throughout the life of the    QImage. The image does not delete the buffer at destruction.    If the image is in an indexed color format, set the color table    for the image using setColorTable().    Unlike the similar QImage constructor that takes a non-const data buffer,    this version will never alter the contents of the buffer.  For example,    calling QImage::bits() will return a deep copy of the image, rather than    the buffer passed to the constructor.  This allows for the efficiency of    constructing a QImage from raw data, without the possibility of the raw    data being changed.*/QImage::QImage(const uchar *data, int width, int height, int bytesPerLine, Format format)    :QPaintDevice(){    d = QImageData::create(const_cast<uchar*>(data), width, height, bytesPerLine, format, true);}/*!    Constructs an image and tries to load the image from the file with    the given \a fileName.    The loader attempts to read the image using the specified \a    format. If the \a format is not specified (which is the default),    the loader probes the file for a header to guess the file format.    If the loading of the image failed, this object is a null image.    The file name can either refer to an actual file on disk or to one    of the application's embedded resources. See the    \l{resources.html}{Resource System} overview for details on how to    embed images and other resource files in the application's    executable.    \sa isNull(), {QImage#Reading and Writing Image Files}{Reading and Writing Image Files}*/QImage::QImage(const QString &fileName, const char *format)    : QPaintDevice(){    d = 0;    load(fileName, format);}/*!    Constructs an image and tries to load the image from the file with    the given \a fileName.    The loader attempts to read the image using the specified \a    format. If the \a format is not specified (which is the default),    the loader probes the file for a header to guess the file format.    If the loading of the image failed, this object is a null image.    The file name can either refer to an actual file on disk or to one    of the application's embedded resources. See the    \l{resources.html}{Resource System} overview for details on how to    embed images and other resource files in the application's    executable.    You can disable this constructor by defining \c    QT_NO_CAST_FROM_ASCII when you compile your applications. This can    be useful, for example, if you want to ensure that all    user-visible strings go through QObject::tr().    \sa QString::fromAscii(), isNull(), {QImage#Reading and Writing    Image Files}{Reading and Writing Image Files}*/#ifndef QT_NO_CAST_FROM_ASCIIQImage::QImage(const char *fileName, const char *format)    : QPaintDevice(){    // ### Qt 5: if you remove the QImage(const QByteArray &) QT3_SUPPORT    // constructor, remove this constructor as well. The constructor here    // exists so that QImage("foo.png") compiles without ambiguity.    d = 0;    load(QString::fromAscii(fileName), format);}#endif#ifndef QT_NO_IMAGEFORMAT_XPMextern bool qt_read_xpm_image_or_array(QIODevice *device, const char * const *source, QImage &image);/*!    Constructs an image from the given \a xpm image.    Make sure that the image is a valid XPM image. Errors are silently    ignored.    Note that it's possible to squeeze the XPM variable a little bit    by using an unusual declaration:    \code        static const char * const start_xpm[] = {            "16 15 8 1",            "a c #cec6bd",        ....    \endcode    The extra \c const makes the entire definition read-only, which is    slightly more efficient (e.g. when the code is in a shared    library) and ROMable when the application is to be stored in ROM.*/QImage::QImage(const char * const xpm[])    : QPaintDevice(){    d = 0;    if (!xpm)        return;    if (!qt_read_xpm_image_or_array(0, xpm, *this))        // Issue: Warning because the constructor may be ambigious        qWarning("QImage::QImage(), XPM is not supported");}#endif // QT_NO_IMAGEFORMAT_XPM/*!    \fn QImage::QImage(const QByteArray &data)    Use the static fromData() function instead.    \oldcode        QByteArray data;        ...        QImage image(data);    \newcode        QByteArray data;        ...        QImage image = QImage::fromData(data);    \endcode*//*!    Constructs a shallow copy of the given \a image.    For more information about shallow copies, see the \l {Implicit    Data Sharing} documentation.    \sa copy()*/QImage::QImage(const QImage &image)    : QPaintDevice(){    d = image.d;    if (d)        d->ref.ref();}#ifdef QT3_SUPPORT/*!    \fn QImage::QImage(int width, int height, int depth, int numColors, Endian bitOrder)    Constructs an image with the given \a width, \a height, \a depth,    \a numColors colors and \a bitOrder.    Use the constructor that accepts a width, a height and a format    (i.e. specifying the depth and bit order), in combination with the    setNumColors() function, instead.    \oldcode        QImage image(width, height, depth, numColors);    \newcode        QImage image(width, height, format);        // For 8 bit images the default number of colors is 256. If        // another number of colors is required it can be specified        // using the setNumColors() function.        image.setNumColors(numColors);    \endcode*/QImage::QImage(int w, int h, int depth, int numColors, Endian bitOrder)    : QPaintDevice(){    d = QImageData::create(QSize(w, h), formatFor(depth, bitOrder), numColors);}/*!    Constructs an image with the given \a size, \a depth, \a numColors    and \a bitOrder.    Use the constructor that accepts a size and a format    (i.e. specifying the depth and bit order), in combination with the    setNumColors() function, instead.    \oldcode        QSize mySize(width, height);        QImage image(mySize, depth, numColors);    \newcode        QSize mySize(width, height);        QImage image(mySize, format);        // For 8 bit images the default number of colors is 256. If        // another number of colors is required it can be specified        // using the setNumColors() function.        image.setNumColors(numColors);    \endcode*/QImage::QImage(const QSize& size, int depth, int numColors, Endian bitOrder)    : QPaintDevice(){    d = QImageData::create(size, formatFor(depth, bitOrder), numColors);}/*!    \fn QImage::QImage(uchar* data, int width, int height, int depth, const QRgb* colortable, int numColors, Endian bitOrder)    Constructs an image with the given \a width, \a height, depth, \a    colortable, \a numColors and \a bitOrder, that uses an existing    memory buffer, \a data.    Use the constructor that accepts a uchar pointer, a width, a    height and a format (i.e. specifying the depth and bit order), in    combination with the setColorTable() function, instead.    \oldcode        uchar *myData;        QRgb *myColorTable;        QImage image(myData, width, height, depth,                               myColorTable, numColors, IgnoreEndian);    \newcode        uchar *myData;        QVector<QRgb> myColorTable;        QImage image(myData, width, height, format);        image.setColorTable(myColorTable);    \endcode*/QImage::QImage(uchar* data, int w, int h, int depth, const QRgb* colortable, int numColors, Endian bitOrder)    : QPaintDevice(){    d = 0;    Format f = formatFor(depth, bitOrder);    if (f == Format_Invalid)        return;    const int bytes_per_line = ((w*depth+31)/32)*4;        // bytes per scanline    if (w <= 0 || h <= 0 || numColors < 0 || !data        || INT_MAX/sizeof(uchar *) < uint(h)        || INT_MAX/uint(depth) < uint(w)        || bytes_per_line <= 0        || INT_MAX/uint(bytes_per_line) < uint(h))        return;                                        // invalid parameter(s)    d = new QImageData;    d->ref.ref();    d->own_data = false;    d->data = data;    d->width = w;    d->height = h;    d->depth = depth;    d->format = f;    if (depth == 32)        numColors = 0;    d->bytes_per_line = bytes_per_line;    d->nbytes = d->bytes_per_line * h;    if (colortable) {        d->colortable.resize(numColors);        for (int i = 0; i < numColors; ++i)            d->colortable[i] = colortable[i];    } else if (numColors) {        setNumColors(numColors);    }}#ifdef Q_WS_QWS/*!    \fn QImage::QImage(uchar* data, int width, int height, int depth, int bytesPerLine, const QRgb* colortable, int numColors, Endian bitOrder)    Constructs an image with the given \a width, \a height, \a depth,    \a bytesPerLine, \a colortable, \a numColors and \a bitOrder, that    uses an existing memory buffer, \a data. The image does not delete    the buffer at destruction.    \warning This constructor is only available in Qtopia Core.    The data has to be 32-bit aligned, and each scanline of data in the image    must also be 32-bit aligned, so it's no longer possible to specify a custom    \a bytesPerLine value.*/QImage::QImage(uchar* data, int w, int h, int depth, int bpl, const QRgb* colortable, int numColors, Endian bitOrder)    : QPaintDevice(){    d = 0;    Format f = formatFor(depth, bitOrder);    if (f == Format_Invalid)        return;    if (!data || w <= 0 || h <= 0 || depth <= 0 || numColors < 0        || INT_MAX/sizeof(uchar *) < uint(h)        || INT_MAX/uint(depth) < uint(w)        || bpl <= 0        || INT_MAX/uint(bpl) < uint(h))        return;                                        // invalid parameter(s)    d = new QImageData;    d->ref.ref();    d->own_data = false;    d->data = data;    d->width = w;    d->height = h;    d->depth = depth;    d->format = f;    if (depth == 32)        numColors = 0;    d->bytes_per_line = bpl;    d->nbytes = d->bytes_per_line * h;    if (colortable) {        d->colortable.resize(numColors);        for (int i = 0; i < numColors; ++i)            d->colortable[i] = colortable[i];    } else if (numColors) {        setNumColors(numColors);    }}#endif // Q_WS_QWS#endif // QT3_SUPPORT/*!    Destroys the image and cleans up.*/QImage::~QImage(){    if (d && !d->ref.deref())        delete d;}/*!    Assigns a shallow copy of the given \a image to this image and    returns a reference to this image.    For more information about shallow copies, see the \l {Implicit    Data Sharing} documentation.    \sa copy(), QImage()*/QImage &QImage::operator=(const QImage &image){    QImageData *x = image.d;    if (x)        x->ref.ref();    x = qAtomicSetPtr(&d, x);    if (x && !x->ref.deref())        delete x;    return *this;}/*!

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -