2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Threading;
20 using System.Threading.Tasks;
25 /// The Image is a widget that allows one to load and display an image file on it,
26 /// be it from a disk file or from a memory region.
29 /// <since_tizen> preview </since_tizen>
30 [Obsolete("This has been deprecated in API12")]
31 public class Image : Widget
33 bool _canScaleUp = true;
34 bool _canScaleDown = true;
36 Color _color = Color.Default;
38 EvasImage _imageObject = null;
41 /// Creates and initializes a new instance of the Image class.
43 /// <param name="parent">The parent is a given container, which will be attached by the image as a child. It's <see cref="EvasObject"/> type.</param>
44 /// <since_tizen> preview </since_tizen>
45 [Obsolete("This has been deprecated in API12")]
46 public Image(EvasObject parent) : base(parent)
48 _clicked = new SmartEvent(this, "clicked");
49 _clicked.On += (s, e) => Clicked?.Invoke(this, EventArgs.Empty);
53 /// Clicked will be triggered when the image is clicked.
55 /// <since_tizen> preview </since_tizen>
56 [Obsolete("This has been deprecated in API12")]
57 public event EventHandler Clicked;
60 /// LoadingCompleted will be triggered when the image is loaded completely.
62 /// <since_tizen> preview </since_tizen>
63 [Obsolete("This has been deprecated in API12")]
64 public event EventHandler LoadingCompleted;
67 /// Clicked will be triggered when the image fails to load.
69 /// <since_tizen> preview </since_tizen>
70 [Obsolete("This has been deprecated in API12")]
71 public event EventHandler LoadingFailed;
74 /// Gets the file that is used as an image.
76 /// <since_tizen> preview </since_tizen>
77 [Obsolete("This has been deprecated in API12")]
82 return Interop.Elementary.elm_image_file_get(RealHandle);
87 /// Sets or gets the smooth effect for an image.
89 /// <since_tizen> preview </since_tizen>
90 [Obsolete("This has been deprecated in API12")]
95 return Interop.Elementary.elm_image_smooth_get(RealHandle);
99 Interop.Elementary.elm_image_smooth_set(RealHandle, value);
104 /// Sets or gets whether scaling is disabled on the object.
106 /// <since_tizen> preview </since_tizen>
107 [Obsolete("This has been deprecated in API12")]
108 public bool IsScaling
112 return !Interop.Elementary.elm_image_no_scale_get(RealHandle);
116 Interop.Elementary.elm_image_no_scale_set(RealHandle, !value);
121 /// Sets or gets whether the object is down resizable.
123 /// <since_tizen> preview </since_tizen>
124 [Obsolete("This has been deprecated in API12")]
125 public bool CanScaleDown
129 return _canScaleDown;
133 _canScaleDown = value;
134 Interop.Elementary.elm_image_resizable_set(RealHandle, _canScaleUp, _canScaleDown);
139 /// Sets or gets whether the object is up resizable.
141 /// <since_tizen> preview </since_tizen>
142 [Obsolete("This has been deprecated in API12")]
143 public bool CanScaleUp
152 Interop.Elementary.elm_image_resizable_set(RealHandle, _canScaleUp, _canScaleDown);
157 /// Sets or gets whether the image fills the entire object area, when keeping the aspect ratio.
159 /// <since_tizen> preview </since_tizen>
160 [Obsolete("This has been deprecated in API12")]
161 public bool CanFillOutside
165 return Interop.Elementary.elm_image_fill_outside_get(RealHandle);
169 Interop.Elementary.elm_image_fill_outside_set(RealHandle, value);
174 /// Sets or gets the prescale size for the image.
176 /// <since_tizen> preview </since_tizen>
177 [Obsolete("This has been deprecated in API12")]
178 public int PrescaleSize
182 return Interop.Elementary.elm_image_prescale_get(RealHandle);
186 Interop.Elementary.elm_image_prescale_set(RealHandle, value);
191 /// Sets or gets whether the original aspect ratio of the image should be kept on resize.
193 /// <since_tizen> preview </since_tizen>
194 [Obsolete("This has been deprecated in API12")]
195 public bool IsFixedAspect
199 return Interop.Elementary.elm_image_aspect_fixed_get(RealHandle);
203 Interop.Elementary.elm_image_aspect_fixed_set(RealHandle, value);
208 /// Sets or gets whether an image object (which supports animation) is to animate itself.
210 /// <since_tizen> preview </since_tizen>
211 [Obsolete("This has been deprecated in API12")]
212 public bool IsAnimated
216 return Interop.Elementary.elm_image_animated_get(RealHandle);
220 Interop.Elementary.elm_image_animated_set(RealHandle, value);
225 /// Gets whether an image object supports animation.
227 /// <since_tizen> preview </since_tizen>
228 [Obsolete("This has been deprecated in API12")]
229 public bool IsAnimatedAvailable
233 return Interop.Elementary.elm_image_animated_available_get(RealHandle);
238 /// Sets or gets whether an image object is under animation.
241 /// An image object, even if it supports animation, will be displayed by default without animation.
242 /// To actually start playing any image object's animation, <see cref="IsAnimated"/> should be TRUE before setting this property true.
244 /// <since_tizen> preview </since_tizen>
245 [Obsolete("This has been deprecated in API12")]
246 public bool IsAnimationPlaying
250 return Interop.Elementary.elm_image_animated_play_get(RealHandle);
254 Interop.Elementary.elm_image_animated_play_set(RealHandle, value);
259 /// Sets or gets whether the image is 'editable'.
261 /// <since_tizen> preview </since_tizen>
262 [Obsolete("This has been deprecated in API12")]
263 public bool IsEditable
267 return Interop.Elementary.elm_image_editable_get(RealHandle);
271 Interop.Elementary.elm_image_editable_set(RealHandle, value);
276 /// Gets the current size of the image.
278 /// <since_tizen> preview </since_tizen>
279 [Obsolete("This has been deprecated in API12")]
280 public Size ObjectSize
284 Interop.Elementary.elm_image_object_size_get(RealHandle, out int w, out int h);
285 return new Size(w, h);
290 /// Sets or gets whether the alpha channel data is being used on the given image object.
292 /// <since_tizen> preview </since_tizen>
293 [Obsolete("This has been deprecated in API12")]
298 if (ImageObject != null)
300 return ImageObject.IsOpaque;
306 if (ImageObject != null)
308 ImageObject.IsOpaque = value;
314 /// Sets or gets the image orientation.
316 /// <since_tizen> preview </since_tizen>
317 [Obsolete("This has been deprecated in API12")]
318 public ImageOrientation Orientation
322 return (ImageOrientation)Interop.Elementary.elm_image_orient_get(RealHandle);
326 Interop.Elementary.elm_image_orient_set(RealHandle, (int)value);
331 /// Sets or gets the image color.
333 /// <since_tizen> preview </since_tizen>
334 [Obsolete("This has been deprecated in API12")]
335 public override Color Color
343 if (ImageObject != null)
347 ImageObject.Color = Color.FromRgba(255, 255, 255, 255);
351 ImageObject.Color = value;
359 /// Sets the background color.
361 /// <since_tizen> preview </since_tizen>
362 [Obsolete("This has been deprecated in API12")]
363 public override Color BackgroundColor
369 SetPartColor("bg", Color.Transparent);
373 SetPartColor("bg", value);
375 _backgroundColor = value;
380 /// Gets the inlined image object of the image widget.
381 /// This property allows one to get the underlying EvasObject of type Image from this elementary widget. It can be useful to do things like save the image to a file, etc.
383 /// <remarks>Be careful not to manipulate it, as it is under the control of the widget.</remarks>
384 /// <since_tizen> preview </since_tizen>
385 [Obsolete("This has been deprecated in API12")]
386 public EvasImage ImageObject
390 if (_imageObject == null)
392 IntPtr evasObj = Interop.Elementary.elm_image_object_get(RealHandle);
393 if (evasObj != IntPtr.Zero)
395 _imageObject = new EvasImage(this, evasObj);
396 _imageObject.Deleted += (s, e) => _imageObject = null;
404 /// Sets the dimensions for an image object's border, a region which is not scaled together with its center ever.
406 /// <param name="left">The border's left width.</param>
407 /// <param name="right">The border's right width.</param>
408 /// <param name="top">The border's top width.</param>
409 /// <param name="bottom">The border's bottom width.</param>
410 /// <since_tizen> preview </since_tizen>
411 [Obsolete("This has been deprecated in API12")]
412 public void SetBorder(int left, int right, int top, int bottom)
414 ImageObject?.SetBorder(left, right, top, bottom);
418 /// Sets or gets if the center part of the given image object (not the border) should be drawn.
421 /// When rendering, the image may be scaled to fit the size of the image object.
422 /// This function sets if the center part of the scaled image is to be drawn or left completely blank, or forced to be solid.
423 /// Very useful for frames and decorations.
425 /// <since_tizen> preview </since_tizen>
426 [Obsolete("This has been deprecated in API12")]
427 public ImageBorderFillMode BorderCenterFillMode
431 if (ImageObject != null)
433 return ImageObject.BorderCenterFillMode;
437 return default(ImageBorderFillMode);
443 if (ImageObject != null)
445 ImageObject.BorderCenterFillMode = value;
451 /// Sets the file that is used as the image's source.
453 /// <param name="file">The path to the file that is used as an image source.</param>
454 /// <returns>(true = success, false = error)</returns>
455 /// <since_tizen> preview </since_tizen>
456 [Obsolete("This has been deprecated in API12")]
457 public bool Load(string file)
460 throw new ArgumentNullException(nameof(file));
462 Interop.Elementary.elm_image_async_open_set(RealHandle, false);
463 Interop.Elementary.elm_image_preload_disabled_set(RealHandle, true);
464 return Interop.Elementary.elm_image_file_set(RealHandle, file, null);
468 /// Sets the URI that is used as the image's source.
470 /// <param name="uri">The URI to the file that is used as an image source.</param>
471 /// <returns>(true = success, false = error)</returns>
472 /// <since_tizen> preview </since_tizen>
473 [Obsolete("This has been deprecated in API12")]
474 public bool Load(Uri uri)
477 throw new ArgumentNullException(nameof(uri));
479 return Load(uri.IsFile ? uri.LocalPath : uri.AbsoluteUri);
483 /// Sets a location in the memory to be used as an image object's source bitmap.
486 /// This function is handy when the contents of an image file are mapped into the memory, for example,
487 /// the format string should be something like "png", "jpg", "tga", "tiff", "bmp" etc, when provided (null, on the contrary).
488 /// This improves the loader performance as it tries the "correct" loader first, before trying a range of other possible loaders until one succeeds.
490 /// <param name="img">The binary data that is used as an image source.</param>
491 /// <param name="size">The size of the binary data blob img.</param>
492 /// <returns>(true = success, false = error)</returns>
493 /// <since_tizen> preview </since_tizen>
494 [Obsolete("This method will be removed. Use Load(Stream stream) instead.")]
495 public unsafe bool Load(byte* img, long size)
498 throw new ArgumentNullException(nameof(img));
500 Interop.Elementary.elm_image_async_open_set(RealHandle, false);
501 Interop.Elementary.elm_image_preload_disabled_set(RealHandle, true);
502 return Interop.Elementary.elm_image_memfile_set(RealHandle, img, size, IntPtr.Zero, IntPtr.Zero);
506 /// Sets the stream that is used as the image's source.
508 /// <param name="stream">The stream that is used as an image source.</param>
509 /// <returns>(true = success, false = error)</returns>
510 /// <since_tizen> preview </since_tizen>
511 [Obsolete("This has been deprecated in API12")]
512 public bool Load(Stream stream)
515 throw new ArgumentNullException(nameof(stream));
517 Interop.Elementary.elm_image_async_open_set(RealHandle, false);
518 Interop.Elementary.elm_image_preload_disabled_set(RealHandle, true);
519 MemoryStream memstream = new MemoryStream();
520 stream.CopyTo(memstream);
523 byte[] dataArr = memstream.ToArray();
524 fixed (byte* data = &dataArr[0])
526 return Interop.Elementary.elm_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
532 /// Sets the file that is used as the image's source with async.
534 /// <param name="file">The path to the file that is used as an image source.</param>
535 /// <param name="cancellationToken">The cancellation token.</param>
536 /// <returns>(true = success, false = error)</returns>
537 /// <since_tizen> preview </since_tizen>
538 [Obsolete("This has been deprecated in API12")]
539 public async Task<bool> LoadAsync(string file, CancellationToken cancellationToken = default(CancellationToken))
542 throw new ArgumentNullException(nameof(file));
544 Interop.Elementary.elm_image_async_open_set(RealHandle, true);
545 Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);
547 var tcs = new TaskCompletionSource<bool>();
549 cancellationToken.Register(() =>
551 if (tcs != null && !tcs.Task.IsCompleted)
557 SmartEvent loadReady = new SmartEvent(this, RealHandle, "load,ready");
558 loadReady.On += (s, e) =>
560 LoadingCompleted?.Invoke(this, EventArgs.Empty);
561 if (tcs != null && !tcs.Task.IsCompleted)
567 SmartEvent loadError = new SmartEvent(this, RealHandle, "load,error");
568 loadError.On += (s, e) =>
570 LoadingFailed?.Invoke(this, EventArgs.Empty);
571 if (tcs != null && !tcs.Task.IsCompleted)
573 tcs.SetResult(false);
580 bool ret = Interop.Elementary.elm_image_file_set(RealHandle, file, null);
583 throw new InvalidOperationException("Failed to set file to Image");
585 // it should be return on main thread, because SmartEvent should be disposed on main thread
586 return await tcs.Task.ConfigureAwait(true);
591 /// Sets the URI that is used as the image's source with async.
593 /// <param name="uri">The URI to the file that is used as an image source.</param>
594 /// <param name="cancellationToken">The cancellation token.</param>
595 /// <returns>(true = success, false = error)</returns>
596 /// <since_tizen> preview </since_tizen>
597 [Obsolete("This has been deprecated in API12")]
598 public Task<bool> LoadAsync(Uri uri, CancellationToken cancellationToken = default(CancellationToken))
601 throw new ArgumentNullException(nameof(uri));
603 return LoadAsync(uri.IsFile ? uri.LocalPath : uri.AbsoluteUri, cancellationToken);
607 /// Sets the stream that is used as the image's source with async.
609 /// <param name="stream">The stream that is used as an image source.</param>
610 /// <param name="cancellationToken">The cancellation token.</param>
611 /// <returns>(true = success, false = error)</returns>
612 /// <since_tizen> preview </since_tizen>
613 [Obsolete("This has been deprecated in API12")]
614 public async Task<bool> LoadAsync(Stream stream, CancellationToken cancellationToken = default(CancellationToken))
617 throw new ArgumentNullException(nameof(stream));
619 Interop.Elementary.elm_image_async_open_set(RealHandle, true);
620 Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);
622 var tcs = new TaskCompletionSource<bool>();
624 cancellationToken.Register(() =>
626 if (tcs != null && !tcs.Task.IsCompleted)
632 SmartEvent loadReady = new SmartEvent(this, RealHandle, "load,ready");
633 loadReady.On += (s, e) =>
635 LoadingCompleted?.Invoke(this, EventArgs.Empty);
636 if (tcs != null && !tcs.Task.IsCompleted)
642 SmartEvent loadError = new SmartEvent(this, RealHandle, "load,error");
643 loadError.On += (s, e) =>
645 LoadingFailed?.Invoke(this, EventArgs.Empty);
646 if (tcs != null && !tcs.Task.IsCompleted)
648 tcs.SetResult(false);
652 using (MemoryStream memstream = new MemoryStream())
656 await stream.CopyToAsync(memstream).ConfigureAwait(true);
660 byte[] dataArr = memstream.ToArray();
661 fixed (byte* data = &dataArr[0])
663 bool ret = Interop.Elementary.elm_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
670 // it should be return on main thread, because SmartEvent should be disposed on main thread
671 return await tcs.Task.ConfigureAwait(true);
676 /// Sets the color of the Color class for a given widget.
678 /// <param name="part">The name of the Color class.</param>
679 /// <param name="color">The struct of the Color class.</param>
680 /// <since_tizen> preview </since_tizen>
681 [Obsolete("This has been deprecated in API12")]
682 public override void SetPartColor(string part, Color color)
684 Interop.Elementary.elm_object_color_class_color_set(Handle, part, color.R * color.A / 255,
685 color.G * color.A / 255,
686 color.B * color.A / 255,
691 /// Gets the color of the Color class for a given widget.
693 /// <param name="part">The name of the Color class.</param>
694 /// <returns>The color object.</returns>
695 /// <since_tizen> preview </since_tizen>
696 [Obsolete("This has been deprecated in API12")]
697 public override Color GetPartColor(string part)
699 Interop.Elementary.elm_object_color_class_color_get(Handle, part, out int r, out int g, out int b, out int a);
700 return new Color((int)(r / (a / 255.0)), (int)(g / (a / 255.0)), (int)(b / (a / 255.0)), a);
704 /// Sets the content at a part of a given container widget.
706 /// <param name="parent">The parent is a given container, which will be attached by the image as a child. It's <see cref="EvasObject"/> type.</param>
707 /// <returns>The new object, otherwise null if it cannot be created.</returns>
708 /// <since_tizen> preview </since_tizen>
709 [Obsolete("This has been deprecated in API12")]
710 protected override IntPtr CreateHandle(EvasObject parent)
712 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
713 Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default");
715 RealHandle = Interop.Elementary.elm_image_add(handle);
716 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
723 /// Enumeration for the fill mode of the image border.
725 /// <since_tizen> preview </since_tizen>
726 [Obsolete("This has been deprecated in API12")]
727 public enum ImageBorderFillMode
730 /// None mode of the image border.
735 /// Default mode of the image border.
740 /// Solid mode of the image border.
746 /// Enumeration for the possible orientation options.
748 /// <since_tizen> preview </since_tizen>
749 [Obsolete("This has been deprecated in API12")]
750 public enum ImageOrientation : int
753 /// No orientation change.
758 /// Rotate 90 degrees clockwise.
763 /// Rotate 180 degrees clockwise.
768 /// Rotate 90 degrees counter-clockwise (i.e., 270 degrees clockwise).
773 /// Flip the image horizontally.
778 /// Flip the image vertically.
783 /// Flip the image along the Y = (width - X) line (bottom-left to top-right).
788 /// Flip the image along the Y = X line (top-left to bottom-right).