docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class PngEncoder

    Managed wrapper around the pngslz native library that encodes raw pixel data to PNG. Used by CaptureImageEncoder when USIM_USE_BUILTIN_PNG_ENCODER is not defined.

    Inheritance
    object
    PngEncoder
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Global Namespace
    Assembly: Unity.SimulationPro.Capture.dll
    Syntax
    public class PngEncoder

    Methods

    Decode(byte[], ref int, ref int, ref ColorType, ref int)

    Decodes an encoded PNG buffer into a raw pixel array.

    Declaration
    public static byte[] Decode(byte[] raw, ref int width, ref int height, ref PngEncoder.ColorType colorType, ref int bitDepth)
    Parameters
    Type Name Description
    byte[] raw

    The encoded PNG data.

    int width

    Output: image width in pixels.

    int height

    Output: image height in pixels.

    PngEncoder.ColorType colorType

    Output: the PNG color type found in the decoded image.

    int bitDepth

    Output: bits per channel in the decoded image.

    Returns
    Type Description
    byte[]

    Decoded raw pixel bytes, or null if decoding fails.

    Encode(byte[], int, int, ColorType, int, PngParam)

    Encodes a raw pixel buffer as a PNG image.

    Declaration
    public static byte[] Encode(byte[] raw, int width, int height, PngEncoder.ColorType colorType, int bitDepth, PngEncoder.PngParam pngParam = PngParam.None)
    Parameters
    Type Name Description
    byte[] raw

    Raw pixel bytes in the layout described by colorType and bitDepth.

    int width

    Image width in pixels.

    int height

    Image height in pixels.

    PngEncoder.ColorType colorType

    The PNG color type for the source data.

    int bitDepth

    Bits per channel in the source data.

    PngEncoder.PngParam pngParam

    Optional flags (e.g. FlipY).

    Returns
    Type Description
    byte[]

    Encoded PNG bytes, or null if encoding fails.

    GetTypeAndDepth(int, int, ref int)

    Maps a GraphicsFormat's block size and component count to the corresponding PNG PngEncoder.ColorType and bit depth.

    Declaration
    public static PngEncoder.ColorType GetTypeAndDepth(int blocksize, int componentCount, ref int bitDepth)
    Parameters
    Type Name Description
    int blocksize

    Total bytes per pixel block (from GetBlockSize(GraphicsFormat)).

    int componentCount

    Number of color components per pixel.

    int bitDepth

    Output: bits per channel computed from the block size and component count.

    Returns
    Type Description
    PngEncoder.ColorType

    The PngEncoder.ColorType corresponding to the given layout, or PNG_INVALID if unsupported.

    Inspect(byte[], ref int, ref int, ref ColorType, ref int, ref int)

    Reads the header of an encoded PNG buffer to determine its dimensions and format without decoding it.

    Declaration
    public static int Inspect(byte[] raw, ref int width, ref int height, ref PngEncoder.ColorType colorType, ref int bitDepth, ref int outsize)
    Parameters
    Type Name Description
    byte[] raw

    The encoded PNG data.

    int width

    Output: image width in pixels.

    int height

    Output: image height in pixels.

    PngEncoder.ColorType colorType

    Output: the PNG color type found in the header.

    int bitDepth

    Output: bits per channel found in the header.

    int outsize

    Output: decoded output buffer size in bytes.

    Returns
    Type Description
    int

    Zero on success; negative on error.

    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)