Class AsyncImageLoader

    Definition

    Namespace:
    Tizen.NUI
    Assembly:
    Tizen.NUI.dll

    Loader class to loading image asynchronously. Request to load image, and get result as PixelData or PixelBuffer

    public class AsyncImageLoader : BaseHandle, IDynamicResourceHandler, INameScope, System.IDisposable
    Inheritance
    object
    BindableObject
    Element
    BaseHandle
    AsyncImageLoader
    Implements
    IDynamicResourceHandler
    INameScope
    System.IDisposable
    Remarks

    Request image loading by Load(). Each Load API return their specific id, which can be used at ImageLoaded / PixelBufferLoaded signal, or Cancel.

    We can create multiple loader. But load task id are not be shared. All API should be called at main thread.

    Examples

    Here is some demo codes to get color picking by Palette

    AsyncImageLoader loader = new AsyncImageLoader();
    loader.PixelBufferLoaded += OnPixelBufferLoaded;
    uint taskId = loader.Load("some_image.jpg");
    ...
    private async void OnPixelBufferLoadedWithColorPalette(object o, AsyncImageLoader.PixelBufferLoadedEventArgs e)
    {
      if (taskId == e.LoadingTaskId)
      {
        PixelBuffer pixelBuffer = e.PixelBuffers[0];
    
        // Copy the pixelData if we need to color picking.
        PixelData pixelData = pixelBuffer.CreatePixelData();
        ImageUrl imageUrl = pixelData.GenerateUrl();
        imageView.ResourceUrl = imageUrl.ToString();
    
        // We need to create new class due to the PixelBuffer become invalidated after callback finished.
        var task = Palette.GenerateAsync(new PixelBuffer(pixelBuffer));
        var palette = await task;
    
        // Get palette result.
        paletteSwatch = palette.GetDominantSwatch();
      }
    }
    ...
    if (paletteSwatch != null)
    {
      swatchInfo.BackgroundColor = paletteSwatch.GetRgb();
      titleLabel.TextColor = paletteSwatch.GetTitleTextColor();
      bodyLabel.TextColor = paletteSwatch.GetBodyTextColor();
    }

    Constructors

    View Source

    AsyncImageLoader()

    Declaration
    public AsyncImageLoader()
    Remarks

    Request image loading by Load(). Each Load API return their specific id, which can be used at ImageLoaded / PixelBufferLoaded signal, or Cancel.

    We can create multiple loader. But load task id are not be shared. All API should be called at main thread.

    Examples

    Here is some demo codes to get color picking by Palette

    AsyncImageLoader loader = new AsyncImageLoader();
    loader.PixelBufferLoaded += OnPixelBufferLoaded;
    uint taskId = loader.Load("some_image.jpg");
    ...
    private async void OnPixelBufferLoadedWithColorPalette(object o, AsyncImageLoader.PixelBufferLoadedEventArgs e)
    {
      if (taskId == e.LoadingTaskId)
      {
        PixelBuffer pixelBuffer = e.PixelBuffers[0];
    
        // Copy the pixelData if we need to color picking.
        PixelData pixelData = pixelBuffer.CreatePixelData();
        ImageUrl imageUrl = pixelData.GenerateUrl();
        imageView.ResourceUrl = imageUrl.ToString();
    
        // We need to create new class due to the PixelBuffer become invalidated after callback finished.
        var task = Palette.GenerateAsync(new PixelBuffer(pixelBuffer));
        var palette = await task;
    
        // Get palette result.
        paletteSwatch = palette.GetDominantSwatch();
      }
    }
    ...
    if (paletteSwatch != null)
    {
      swatchInfo.BackgroundColor = paletteSwatch.GetRgb();
      titleLabel.TextColor = paletteSwatch.GetTitleTextColor();
      bodyLabel.TextColor = paletteSwatch.GetBodyTextColor();
    }

    Methods

    View Source

    Cancel(uint)

    Declaration
    public bool Cancel(uint loadingTaskId)
    Parameters
    Type Name Description
    uint loadingTaskId
    Returns
    Type Description
    bool
    Remarks

    Request image loading by Load(). Each Load API return their specific id, which can be used at ImageLoaded / PixelBufferLoaded signal, or Cancel.

    We can create multiple loader. But load task id are not be shared. All API should be called at main thread.

    Examples

    Here is some demo codes to get color picking by Palette

    AsyncImageLoader loader = new AsyncImageLoader();
    loader.PixelBufferLoaded += OnPixelBufferLoaded;
    uint taskId = loader.Load("some_image.jpg");
    ...
    private async void OnPixelBufferLoadedWithColorPalette(object o, AsyncImageLoader.PixelBufferLoadedEventArgs e)
    {
      if (taskId == e.LoadingTaskId)
      {
        PixelBuffer pixelBuffer = e.PixelBuffers[0];
    
        // Copy the pixelData if we need to color picking.
        PixelData pixelData = pixelBuffer.CreatePixelData();
        ImageUrl imageUrl = pixelData.GenerateUrl();
        imageView.ResourceUrl = imageUrl.ToString();
    
        // We need to create new class due to the PixelBuffer become invalidated after callback finished.
        var task = Palette.GenerateAsync(new PixelBuffer(pixelBuffer));
        var palette = await task;
    
        // Get palette result.
        paletteSwatch = palette.GetDominantSwatch();
      }
    }
    ...
    if (paletteSwatch != null)
    {
      swatchInfo.BackgroundColor = paletteSwatch.GetRgb();
      titleLabel.TextColor = paletteSwatch.GetTitleTextColor();
      bodyLabel.TextColor = paletteSwatch.GetBodyTextColor();
    }
    View Source

    CancelAll()

    Declaration
    public void CancelAll()
    Remarks

    Request image loading by Load(). Each Load API return their specific id, which can be used at ImageLoaded / PixelBufferLoaded signal, or Cancel.

    We can create multiple loader. But load task id are not be shared. All API should be called at main thread.

    Examples

    Here is some demo codes to get color picking by Palette

    AsyncImageLoader loader = new AsyncImageLoader();
    loader.PixelBufferLoaded += OnPixelBufferLoaded;
    uint taskId = loader.Load("some_image.jpg");
    ...
    private async void OnPixelBufferLoadedWithColorPalette(object o, AsyncImageLoader.PixelBufferLoadedEventArgs e)
    {
      if (taskId == e.LoadingTaskId)
      {
        PixelBuffer pixelBuffer = e.PixelBuffers[0];
    
        // Copy the pixelData if we need to color picking.
        PixelData pixelData = pixelBuffer.CreatePixelData();
        ImageUrl imageUrl = pixelData.GenerateUrl();
        imageView.ResourceUrl = imageUrl.ToString();
    
        // We need to create new class due to the PixelBuffer become invalidated after callback finished.
        var task = Palette.GenerateAsync(new PixelBuffer(pixelBuffer));
        var palette = await task;
    
        // Get palette result.
        paletteSwatch = palette.GetDominantSwatch();
      }
    }
    ...
    if (paletteSwatch != null)
    {
      swatchInfo.BackgroundColor = paletteSwatch.GetRgb();
      titleLabel.TextColor = paletteSwatch.GetTitleTextColor();
      bodyLabel.TextColor = paletteSwatch.GetBodyTextColor();
    }
    View Source

    Dispose(DisposeTypes)

    You can override it to clean-up your own resources

    Declaration
    protected override void Dispose(DisposeTypes type)
    Parameters
    Type Name Description
    DisposeTypes type

    DisposeTypes

    Overrides
    BaseHandle.Dispose(DisposeTypes)
    Remarks

    Request image loading by Load(). Each Load API return their specific id, which can be used at ImageLoaded / PixelBufferLoaded signal, or Cancel.

    We can create multiple loader. But load task id are not be shared. All API should be called at main thread.

    View Source

    Load(string, uint, uint, FittingModeType, SamplingModeType, bool)

    Declaration
    public uint Load(string url, uint desiredWidth, uint desiredHeight, FittingModeType fittingMode, SamplingModeType samplingMode, bool orientationCorrection)
    Parameters
    Type Name Description
    string url
    uint desiredWidth
    uint desiredHeight
    FittingModeType fittingMode
    SamplingModeType samplingMode
    bool orientationCorrection
    Returns
    Type Description
    uint
    Remarks

    Request image loading by Load(). Each Load API return their specific id, which can be used at ImageLoaded / PixelBufferLoaded signal, or Cancel.

    We can create multiple loader. But load task id are not be shared. All API should be called at main thread.

    Examples

    Here is some demo codes to get color picking by Palette

    AsyncImageLoader loader = new AsyncImageLoader();
    loader.PixelBufferLoaded += OnPixelBufferLoaded;
    uint taskId = loader.Load("some_image.jpg");
    ...
    private async void OnPixelBufferLoadedWithColorPalette(object o, AsyncImageLoader.PixelBufferLoadedEventArgs e)
    {
      if (taskId == e.LoadingTaskId)
      {
        PixelBuffer pixelBuffer = e.PixelBuffers[0];
    
        // Copy the pixelData if we need to color picking.
        PixelData pixelData = pixelBuffer.CreatePixelData();
        ImageUrl imageUrl = pixelData.GenerateUrl();
        imageView.ResourceUrl = imageUrl.ToString();
    
        // We need to create new class due to the PixelBuffer become invalidated after callback finished.
        var task = Palette.GenerateAsync(new PixelBuffer(pixelBuffer));
        var palette = await task;
    
        // Get palette result.
        paletteSwatch = palette.GetDominantSwatch();
      }
    }
    ...
    if (paletteSwatch != null)
    {
      swatchInfo.BackgroundColor = paletteSwatch.GetRgb();
      titleLabel.TextColor = paletteSwatch.GetTitleTextColor();
      bodyLabel.TextColor = paletteSwatch.GetBodyTextColor();
    }
    View Source

    Load(string, uint, uint)

    Declaration
    public uint Load(string url, uint desiredWidth, uint desiredHeight)
    Parameters
    Type Name Description
    string url
    uint desiredWidth
    uint desiredHeight
    Returns
    Type Description
    uint
    Remarks

    Request image loading by Load(). Each Load API return their specific id, which can be used at ImageLoaded / PixelBufferLoaded signal, or Cancel.

    We can create multiple loader. But load task id are not be shared. All API should be called at main thread.

    Examples

    Here is some demo codes to get color picking by Palette

    AsyncImageLoader loader = new AsyncImageLoader();
    loader.PixelBufferLoaded += OnPixelBufferLoaded;
    uint taskId = loader.Load("some_image.jpg");
    ...
    private async void OnPixelBufferLoadedWithColorPalette(object o, AsyncImageLoader.PixelBufferLoadedEventArgs e)
    {
      if (taskId == e.LoadingTaskId)
      {
        PixelBuffer pixelBuffer = e.PixelBuffers[0];
    
        // Copy the pixelData if we need to color picking.
        PixelData pixelData = pixelBuffer.CreatePixelData();
        ImageUrl imageUrl = pixelData.GenerateUrl();
        imageView.ResourceUrl = imageUrl.ToString();
    
        // We need to create new class due to the PixelBuffer become invalidated after callback finished.
        var task = Palette.GenerateAsync(new PixelBuffer(pixelBuffer));
        var palette = await task;
    
        // Get palette result.
        paletteSwatch = palette.GetDominantSwatch();
      }
    }
    ...
    if (paletteSwatch != null)
    {
      swatchInfo.BackgroundColor = paletteSwatch.GetRgb();
      titleLabel.TextColor = paletteSwatch.GetTitleTextColor();
      bodyLabel.TextColor = paletteSwatch.GetBodyTextColor();
    }
    View Source

    Load(string)

    Declaration
    public uint Load(string url)
    Parameters
    Type Name Description
    string url
    Returns
    Type Description
    uint
    Remarks

    Request image loading by Load(). Each Load API return their specific id, which can be used at ImageLoaded / PixelBufferLoaded signal, or Cancel.

    We can create multiple loader. But load task id are not be shared. All API should be called at main thread.

    Examples

    Here is some demo codes to get color picking by Palette

    AsyncImageLoader loader = new AsyncImageLoader();
    loader.PixelBufferLoaded += OnPixelBufferLoaded;
    uint taskId = loader.Load("some_image.jpg");
    ...
    private async void OnPixelBufferLoadedWithColorPalette(object o, AsyncImageLoader.PixelBufferLoadedEventArgs e)
    {
      if (taskId == e.LoadingTaskId)
      {
        PixelBuffer pixelBuffer = e.PixelBuffers[0];
    
        // Copy the pixelData if we need to color picking.
        PixelData pixelData = pixelBuffer.CreatePixelData();
        ImageUrl imageUrl = pixelData.GenerateUrl();
        imageView.ResourceUrl = imageUrl.ToString();
    
        // We need to create new class due to the PixelBuffer become invalidated after callback finished.
        var task = Palette.GenerateAsync(new PixelBuffer(pixelBuffer));
        var palette = await task;
    
        // Get palette result.
        paletteSwatch = palette.GetDominantSwatch();
      }
    }
    ...
    if (paletteSwatch != null)
    {
      swatchInfo.BackgroundColor = paletteSwatch.GetRgb();
      titleLabel.TextColor = paletteSwatch.GetTitleTextColor();
      bodyLabel.TextColor = paletteSwatch.GetBodyTextColor();
    }
    View Source

    ReleaseSwigCPtr(HandleRef)

    Declaration
    protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
    Parameters
    Type Name Description
    System.Runtime.InteropServices.HandleRef swigCPtr
    Overrides
    BaseHandle.ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef)
    Remarks

    Request image loading by Load(). Each Load API return their specific id, which can be used at ImageLoaded / PixelBufferLoaded signal, or Cancel.

    We can create multiple loader. But load task id are not be shared. All API should be called at main thread.

    Examples

    Here is some demo codes to get color picking by Palette

    AsyncImageLoader loader = new AsyncImageLoader();
    loader.PixelBufferLoaded += OnPixelBufferLoaded;
    uint taskId = loader.Load("some_image.jpg");
    ...
    private async void OnPixelBufferLoadedWithColorPalette(object o, AsyncImageLoader.PixelBufferLoadedEventArgs e)
    {
      if (taskId == e.LoadingTaskId)
      {
        PixelBuffer pixelBuffer = e.PixelBuffers[0];
    
        // Copy the pixelData if we need to color picking.
        PixelData pixelData = pixelBuffer.CreatePixelData();
        ImageUrl imageUrl = pixelData.GenerateUrl();
        imageView.ResourceUrl = imageUrl.ToString();
    
        // We need to create new class due to the PixelBuffer become invalidated after callback finished.
        var task = Palette.GenerateAsync(new PixelBuffer(pixelBuffer));
        var palette = await task;
    
        // Get palette result.
        paletteSwatch = palette.GetDominantSwatch();
      }
    }
    ...
    if (paletteSwatch != null)
    {
      swatchInfo.BackgroundColor = paletteSwatch.GetRgb();
      titleLabel.TextColor = paletteSwatch.GetTitleTextColor();
      bodyLabel.TextColor = paletteSwatch.GetBodyTextColor();
    }

    Events

    View Source

    ImageLoaded

    Event when pixel data are loaded. null or empty PixelData if load failed.

    Declaration
    public event EventHandler<AsyncImageLoader.ImageLoadedEventArgs> ImageLoaded
    Event Type
    Type Description
    EventHandler<><ImageLoadedEventArgs>
    Remarks

    We cannot use both ImageLoaded and PixelBufferLoaded events. If we use PixelBufferLoaded, ImageLoaded will be ignored.

    View Source

    PixelBufferLoaded

    Event when pixel buffers are loaded. null or empty PixelBuffer list if load failed.

    Declaration
    public event EventHandler<AsyncImageLoader.PixelBufferLoadedEventArgs> PixelBufferLoaded
    Event Type
    Type Description
    EventHandler<><PixelBufferLoadedEventArgs>
    Remarks

    We cannot use both ImageLoaded and PixelBufferLoaded events. If we use PixelBufferLoaded, ImageLoaded will be ignored.

    Implements

    IDynamicResourceHandler
    INameScope
    System.IDisposable

    Extension Methods

    EXamlExtensions.LoadFromEXamlByRelativePath<T>(T, string)
    Extensions.LoadFromXaml<TXaml>(TXaml, string)
    Extensions.LoadFromXaml<TXaml>(TXaml, Type)
    Extensions.LoadFromXamlFile<TXaml>(TXaml, string)
    BindableObjectExtensions.SetBinding(BindableObject, BindableProperty, string, BindingMode, IValueConverter, string)
    NameScopeExtensions.FindByName<T>(Element, string)
    • View Source
    Back to top Copyright © 2016-2025 Samsung
    Generated by DocFX