View Source Scenic.Assets.Stream.Image (Scenic v0.11.2)

This module helps you to prepare images, in the form of a compressed blob such as a jpg or png file, that are to be streamed and displayed through the Scenic.Assets.Stream module.

A typical use case is receiving pre-compressed images from a physical camera, then streaming them as the fill of a rect in a scene.

This module is very simple. The only function is from_binary/1, where you supply a binary that is a valid compressed image format. That format is verified and the metadata is parsed out of it.

The result is a term that can be supplied to the Scenic.Assets.Stream module.

Example:

alias Scenic.Assets.Stream

def handle_info( {:camera_frame, bin}, state ) do
  # If the supplied bin is not a valid image, let it crash
  {:ok, img} = Stream.Image.from_binary( bin )
  Stream.put( "camera", img )
  { :noreply, state }
end

Link to this section Summary

Functions

Create a streamable image resource from a compressed image binary.

Link to this section Types

@type meta() :: {width :: pos_integer(), height :: pos_integer(), mime :: String.t()}
@type t() :: {Scenic.Assets.Stream.Image, meta :: meta(), data :: binary()}

Link to this section Functions

@spec from_binary(bin :: binary()) :: {:ok, t()} | {:error, :invalid}

Create a streamable image resource from a compressed image binary.

On success, this returns {:ok, img}

The supplied binary must be a valid jpeg or png format. If it is either invalid or an unrecognized format, this will return {:error, :invalid}