Class AsyncImageLoader
Definition
- 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
- Implements
-
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 SourceAsyncImageLoader()
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 SourceCancel(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
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.
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
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 SourceImageLoaded
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.
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.