Module: ChunkyPNG::Canvas::StreamExporting

### Home Classes Methods

### In Files

- lib/chunky_png/canvas/stream_exporting.rb

### Methods

- #to_abgr_stream
- #to_alpha_channel_stream
- #to_grayscale_stream
- #to_rgb_stream
- #to_rgba_stream

### Files

- BENCHMARKING.rdoc
- CHANGELOG.rdoc
- CONTRIBUTING.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- ChunkyPNG
- ChunkyPNG::CRCMismatch
- ChunkyPNG::Canvas
- ChunkyPNG::Canvas::Adam7Interlacing
- ChunkyPNG::Canvas::DataUrlExporting
- ChunkyPNG::Canvas::DataUrlImporting
- ChunkyPNG::Canvas::Drawing
- ChunkyPNG::Canvas::Masking
- ChunkyPNG::Canvas::Operations
- ChunkyPNG::Canvas::PNGDecoding
- ChunkyPNG::Canvas::PNGEncoding
- ChunkyPNG::Canvas::Resampling
- ChunkyPNG::Canvas::StreamExporting
- ChunkyPNG::Canvas::StreamImporting
- ChunkyPNG::Chunk
- ChunkyPNG::Chunk::Base
- ChunkyPNG::Chunk::CompressedText
- ChunkyPNG::Chunk::End
- ChunkyPNG::Chunk::Generic
- ChunkyPNG::Chunk::Header
- ChunkyPNG::Chunk::ImageData
- ChunkyPNG::Chunk::InternationalText
- ChunkyPNG::Chunk::Palette
- ChunkyPNG::Chunk::Text
- ChunkyPNG::Chunk::Transparency
- ChunkyPNG::Color
- ChunkyPNG::Datastream
- ChunkyPNG::Dimension
- ChunkyPNG::Exception
- ChunkyPNG::ExpectationFailed
- ChunkyPNG::Image
- ChunkyPNG::NotSupported
- ChunkyPNG::OutOfBounds
- ChunkyPNG::Palette
- ChunkyPNG::Point
- ChunkyPNG::RMagick
- ChunkyPNG::SignatureMismatch
- ChunkyPNG::Vector
- Enumerable
- String

No matching classes.

# ChunkyPNG::Canvas::StreamExporting

Methods to save load a canvas from to stream, encoded in RGB, RGBA, BGR or ABGR format.

### Public Instance Methods

to_abgr_stream() click to toggle source

Creates an ABGR-formatted pixelstream with the pixel data from this canvas.

Note that this format is fast but bloated, because no compression is used and the internal representation is left intact. To reconstruct the canvas, the width and height should be known.

@return [String] The RGBA-formatted pixel data.

    # File lib/chunky_png/canvas/stream_exporting.rb, line 53
    def to_abgr_stream
      pixels.pack('V*')
    end

to_alpha_channel_stream() click to toggle source

Creates a stream of the alpha channel of this canvas.

@return [String] The 0-255 alpha values of all pixels packed as string

    # File lib/chunky_png/canvas/stream_exporting.rb, line 32
    def to_alpha_channel_stream
      pixels.pack('C*')
    end

to_grayscale_stream() click to toggle source

Creates a grayscale stream of this canvas.

This method assume sthat this image is fully grayscale, i.e. R = G = B for every pixel. The alpha channel will not be included in the stream.

@return [String] The 0-255 grayscale values of all pixels packed as string.

    # File lib/chunky_png/canvas/stream_exporting.rb, line 42
    def to_grayscale_stream
      pixels.pack('nX' * pixels.length)
    end

to_rgb_stream() click to toggle source

Creates an RGB-formatted pixelstream with the pixel data from this canvas.

Note that this format is fast but bloated, because no compression is used and the internal representation is almost left intact. To reconstruct the canvas, the width and height should be known.

@return [String] The RGB-formatted pixel data.

    # File lib/chunky_png/canvas/stream_exporting.rb, line 25
    def to_rgb_stream
      pixels.pack('NX' * pixels.length)
    end

to_rgba_stream() click to toggle source

Creates an RGB-formatted pixelstream with the pixel data from this canvas.

Note that this format is fast but bloated, because no compression is used and the internal representation is left intact. To reconstruct the canvas, the width and height should be known.

@return [String] The RGBA-formatted pixel data.

    # File lib/chunky_png/canvas/stream_exporting.rb, line 14
    def to_rgba_stream
      pixels.pack('N*')
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.