• PySide 模块
  • PySide.QtGui
  • 内容表

    上一话题

    QPictureIO

    下一话题

    QIconEngine

    QImageIOHandler

    概要

    函数

    虚函数

    详细描述

    PySide.QtGui.QImageIOHandler class defines the common image I/O interface for all image formats in Qt.

    Qt uses PySide.QtGui.QImageIOHandler for reading and writing images through PySide.QtGui.QImageReader and PySide.QtGui.QImageWriter . You can also derive from this class to write your own image format handler using Qt's plugin mechanism.

    调用 PySide.QtGui.QImageIOHandler.setDevice() to assign a device to the handler, and PySide.QtGui.QImageIOHandler.setFormat() to assign a format to it. One PySide.QtGui.QImageIOHandler may support more than one image format. PySide.QtGui.QImageIOHandler.canRead() returns true if an image can be read from the device, and PySide.QtGui.QImageIOHandler.read() and PySide.QtGui.QImageIOHandler.write() return true if reading or writing an image was completed successfully.

    PySide.QtGui.QImageIOHandler also has support for animations formats, through the functions PySide.QtGui.QImageIOHandler.loopCount() , PySide.QtGui.QImageIOHandler.imageCount() , PySide.QtGui.QImageIOHandler.nextImageDelay() and PySide.QtGui.QImageIOHandler.currentImageNumber() .

    In order to determine what options an image handler supports, Qt will call PySide.QtGui.QImageIOHandler.supportsOption() and PySide.QtGui.QImageIOHandler.setOption() . Make sure to reimplement these functions if you can provide support for any of the options in the QImageIOHandler.ImageOption 枚举。

    To write your own image handler, you must at least reimplement PySide.QtGui.QImageIOHandler.canRead() and PySide.QtGui.QImageIOHandler.read() . Then create a QImageIOPlugin that can create the handler. Finally, install your plugin, and PySide.QtGui.QImageReader and PySide.QtGui.QImageWriter will then automatically load the plugin, and start using it.

    class PySide.QtGui. QImageIOHandler

    构造 PySide.QtGui.QImageIOHandler 对象。

    PySide.QtGui.QImageIOHandler. ImageOption

    This enum describes the different options supported by PySide.QtGui.QImageIOHandler . Some options are used to query an image for properties, and others are used to toggle the way in which an image should be written.

    常量 描述
    QImageIOHandler.Size The original size of an image. A handler that supports this option is expected to read the size of the image from the image metadata, and return this size from PySide.QtGui.QImageIOHandler.option() 作为 PySide.QtCore.QSize .
    QImageIOHandler.ClipRect The clip rect, or ROI (Region Of Interest). A handler that supports this option is expected to only read the provided PySide.QtCore.QRect area from the original image in PySide.QtGui.QImageIOHandler.read() , before any other transformation is applied.
    QImageIOHandler.ScaledSize The scaled size of the image. A handler that supports this option is expected to scale the image to the provided size (a PySide.QtCore.QSize ), after applying any clip rect transformation ( ClipRect ). If the handler does not support this option, PySide.QtGui.QImageReader will perform the scaling after the image has been read.
    QImageIOHandler.ScaledClipRect The scaled clip rect (or ROI, Region Of Interest) of the image. A handler that supports this option is expected to apply the provided clip rect (a PySide.QtCore.QRect ), after applying any scaling (ScaleSize) or regular clipping ( ClipRect ). If the handler does not support this option, PySide.QtGui.QImageReader will apply the scaled clip rect after the image has been read.
    QImageIOHandler.Description The image description. Some image formats, such as GIF and PNG, allow embedding of text or comments into the image data (e.g., for storing copyright information). It's common that the text is stored in key-value pairs, but some formats store all text in one continuous block. PySide.QtGui.QImageIOHandler returns the text as one PySide.QtCore.QString , where keys and values are separated by a ‘:', and keys-value pairs are separated by two newlines (nn). For example, “Title: SunsetnnAuthor: Jim SmithnSarah Jonesnn”. Formats that store text in a single block can use “Description” as the key.
    QImageIOHandler.CompressionRatio The compression ratio of the image data. A handler that supports this option is expected to set its compression rate depending on the value of this option (an int) when writing.
    QImageIOHandler.Gamma The gamma level of the image. A handler that supports this option is expected to set the image gamma level depending on the value of this option (a float) when writing.
    QImageIOHandler.Quality The quality level of the image. A handler that supports this option is expected to set the image quality level depending on the value of this option (an int) when writing.
    QImageIOHandler.Name The name of the image. A handler that supports this option is expected to read the name from the image metadata and return this as a PySide.QtCore.QString , or when writing an image it is expected to store the name in the image metadata.
    QImageIOHandler.SubType The subtype of the image. A handler that supports this option can use the subtype value to help when reading and writing images. For example, a PPM handler may have a subtype value of “ppm” or “ppmraw”.
    QImageIOHandler.IncrementalReading A handler that supports this option is expected to read the image in several passes, as if it was an animation. PySide.QtGui.QImageReader will treat the image as an animation.
    QImageIOHandler.Endianness The endianness of the image. Certain image formats can be stored as BigEndian or LittleEndian. A handler that supports Endianness uses the value of this option to determine how the image should be stored.
    QImageIOHandler.Animation Image formats that support animation return true for this value in PySide.QtGui.QImageIOHandler.supportsOption() ; otherwise, false is returned.
    QImageIOHandler.BackgroundColor Certain image formats allow the background color to be specified. A handler that supports BackgroundColor initializes the background color to this option (a PySide.QtGui.QColor ) when reading an image.
    QImageIOHandler.ImageFormat The image's data format returned by the handler. This can be any of the formats listed in QImage.Format .
    PySide.QtGui.QImageIOHandler. canRead ( )
    返回类型: PySide.QtCore.bool

    Returns true if an image can be read from the device (i.e., the image format is supported, the device can be read from and the initial header information suggests that the image can be read); otherwise returns false.

    When reimplementing PySide.QtGui.QImageIOHandler.canRead() , make sure that the I/O device ( PySide.QtGui.QImageIOHandler.device() ) is left in its original state (e.g., by using peek() rather than PySide.QtGui.QImageIOHandler.read() ).

    另请参阅

    PySide.QtGui.QImageIOHandler.read() QIODevice.peek()

    PySide.QtGui.QImageIOHandler. currentImageNumber ( )
    返回类型: PySide.QtCore.int

    For image formats that support animation, this function returns the sequence number of the current image in the animation. If this function is called before any image is PySide.QtGui.QImageIOHandler.read() , -1 is returned. The number of the first image in the sequence is 0.

    If the image format does not support animation, 0 is returned.

    PySide.QtGui.QImageIOHandler. currentImageRect ( )
    返回类型: PySide.QtCore.QRect

    Returns the rect of the current image. If no rect is defined for the image, and empty QRect() 被返回。

    This function is useful for animations, where only parts of the frame may be updated at a time.

    PySide.QtGui.QImageIOHandler. device ( )
    返回类型: PySide.QtCore.QIODevice

    Returns the device currently assigned to the PySide.QtGui.QImageIOHandler . If not device has been assigned, 0 is returned.

    PySide.QtGui.QImageIOHandler. format ( )
    返回类型: PySide.QtCore.QByteArray

    Returns the format that is currently assigned to PySide.QtGui.QImageIOHandler . If no format has been assigned, an empty string is returned.

    PySide.QtGui.QImageIOHandler. imageCount ( )
    返回类型: PySide.QtCore.int

    For image formats that support animation, this function returns the number of images in the animation. If the image format does not support animation, or if it is unable to determine the number of images, 0 is returned.

    The default implementation returns 1 if PySide.QtGui.QImageIOHandler.canRead() returns true; otherwise 0 is returned.

    PySide.QtGui.QImageIOHandler. jumpToImage ( imageNumber )
    参数: imageNumber PySide.QtCore.int
    返回类型: PySide.QtCore.bool

    For image formats that support animation, this function jumps to the image whose sequence number is imageNumber . The next call to PySide.QtGui.QImageIOHandler.read() will attempt to read this image.

    The default implementation does nothing, and returns false.

    PySide.QtGui.QImageIOHandler. jumpToNextImage ( )
    返回类型: PySide.QtCore.bool

    For image formats that support animation, this function jumps to the next image.

    The default implementation does nothing, and returns false.

    PySide.QtGui.QImageIOHandler. loopCount ( )
    返回类型: PySide.QtCore.int

    For image formats that support animation, this function returns the number of times the animation should loop. If the image format does not support animation, 0 is returned.

    PySide.QtGui.QImageIOHandler. nextImageDelay ( )
    返回类型: PySide.QtCore.int

    For image formats that support animation, this function returns the number of milliseconds to wait until reading the next image. If the image format does not support animation, 0 is returned.

    PySide.QtGui.QImageIOHandler. option ( option )
    参数: option PySide.QtGui.QImageIOHandler.ImageOption
    返回类型: object

    Returns the value assigned to option 作为 PySide.QtCore.QVariant . The type of the value depends on the option. For example, option(Size) returns a PySide.QtCore.QSize variant.

    PySide.QtGui.QImageIOHandler. read ( image )
    参数: image PySide.QtGui.QImage
    返回类型: PySide.QtCore.bool

    Read an image from the device, and stores it in image . Returns true if the image is successfully read; otherwise returns false.

    For image formats that support incremental loading, and for animation formats, the image handler can assume that image points to the previous frame.

    PySide.QtGui.QImageIOHandler. setDevice ( device )
    参数: device PySide.QtCore.QIODevice

    Sets the device of the PySide.QtGui.QImageIOHandler to device . The image handler will use this device when reading and writing images.

    The device can only be set once and must be set before calling PySide.QtGui.QImageIOHandler.canRead() , PySide.QtGui.QImageIOHandler.read() , PySide.QtGui.QImageIOHandler.write() , etc. If you need to read multiple files, construct multiple instances of the appropriate PySide.QtGui.QImageIOHandler 子类。

    PySide.QtGui.QImageIOHandler. setFormat ( format )
    参数: format PySide.QtCore.QByteArray

    Sets the format of the PySide.QtGui.QImageIOHandler to format . The format is most useful for handlers that support multiple image formats.

    This function is declared const so that it can be called from PySide.QtGui.QImageIOHandler.canRead() .

    PySide.QtGui.QImageIOHandler. setOption ( option , value )
    参数:

    设置选项 option 采用值 value .

    另请参阅

    PySide.QtGui.QImageIOHandler.option() QImageIOHandler.ImageOption

    PySide.QtGui.QImageIOHandler. supportsOption ( option )
    参数: option PySide.QtGui.QImageIOHandler.ImageOption
    返回类型: PySide.QtCore.bool

    返回 true 若 PySide.QtGui.QImageIOHandler 支持选项 option ; otherwise returns false. For example, if the PySide.QtGui.QImageIOHandler 支持 Size 选项,supportsOption(Size) 必须返回 true。

    PySide.QtGui.QImageIOHandler. write ( image )
    参数: image PySide.QtGui.QImage
    返回类型: PySide.QtCore.bool

    写入图像 image to the assigned device. Returns true on success; otherwise returns false.

    The default implementation does nothing, and simply returns false.