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.
18 using System.Collections.Generic;
19 using System.ComponentModel;
26 /// This group provides the functions for image objects.
28 /// <since_tizen> preview </since_tizen>
29 public class EvasImage : EvasObject
31 EvasObject _source = null;
32 IntPtr _handle = IntPtr.Zero;
35 /// Creates and initializes a new instance of the EvasImage class.
37 /// <param name="parent">The parent is a given container, which will be attached by EvasImage as a child. It's <see cref="EvasObject"/> type.</param>
38 /// <since_tizen> preview </since_tizen>
39 public EvasImage(EvasObject parent) : base(parent)
43 internal EvasImage(EvasObject parent, IntPtr handle) : base()
50 /// Sets or gets the source file from where an image object must fetch the real image data.
52 /// <since_tizen> preview </since_tizen>
58 Interop.Evas.evas_object_image_file_get(RealHandle, out file, out key);
63 Interop.Evas.evas_object_image_file_set(RealHandle, value, null);
68 /// Sets or gets the source object to be visible.
70 /// <since_tizen> preview </since_tizen>
71 public bool IsSourceVisible
75 return Interop.Evas.evas_object_image_source_visible_get(RealHandle);
79 Interop.Evas.evas_object_image_source_visible_set(RealHandle, value);
84 /// Sets or gets whether an object is clipped by the source object's clipper.
86 /// <since_tizen> preview </since_tizen>
87 public bool IsSourceClipped
91 return Interop.Evas.evas_object_image_source_clip_get(RealHandle);
95 Interop.Evas.evas_object_image_source_clip_set(RealHandle, value);
100 /// Sets or gets if the center part of the given image object (not the border) should be drawn.
103 /// When rendering, the image may be scaled to fit the size of the image object.
104 /// This function sets if the center part of the scaled image is to be drawn or left completely blank, or forced to be solid.
105 /// Very useful for frames and decorations.
107 /// <since_tizen> preview </since_tizen>
108 public ImageBorderFillMode BorderCenterFillMode
112 return (ImageBorderFillMode)Interop.Evas.evas_object_image_border_center_fill_get(RealHandle);
116 Interop.Evas.evas_object_image_border_center_fill_set(RealHandle, (int)value);
121 /// Sets or gets whether the image object's fill property should track the object's size.
123 /// <since_tizen> preview </since_tizen>
128 return Interop.Evas.evas_object_image_filled_get(RealHandle);
132 Interop.Evas.evas_object_image_filled_set(RealHandle, value);
137 /// Sets or gets the scaling factor (multiplier) for the borders of the image object.
139 /// <since_tizen> preview </since_tizen>
140 public double BorderScale
144 return Interop.Evas.evas_object_image_border_scale_get(RealHandle);
148 Interop.Evas.evas_object_image_border_scale_set(RealHandle, value);
153 /// Sets or gets the size of the given image object.
155 /// <since_tizen> preview </since_tizen>
161 Interop.Evas.evas_object_image_size_get(RealHandle, out w, out h);
162 return new Size(w, h);
166 Interop.Evas.evas_object_image_size_set(RealHandle, value.Width, value.Height);
171 /// Gets the row stride of the given image object.
173 /// <since_tizen> preview </since_tizen>
178 return Interop.Evas.evas_object_image_stride_get(RealHandle);
183 /// Sets or gets whether the alpha channel data is being used on the given image object.
185 /// <since_tizen> preview </since_tizen>
190 return !Interop.Evas.evas_object_image_alpha_get(RealHandle);
194 Interop.Evas.evas_object_image_alpha_set(RealHandle, !value);
199 /// Sets or gets whether to use a high-quality image scaling algorithm on the given image object.
201 /// <since_tizen> preview </since_tizen>
202 public bool IsSmoothScaled
206 return Interop.Evas.evas_object_image_smooth_scale_get(RealHandle);
210 Interop.Evas.evas_object_image_smooth_scale_set(RealHandle, value);
215 /// Sets how to fill an image object's drawing rectangle given the (real) image bound to it.
217 /// <param name="geometry">The rectangle of the given image object that the image will be drawn to.</param>
218 /// <since_tizen> preview </since_tizen>
219 public void SetFill(Rect geometry)
221 Interop.Evas.evas_object_image_fill_set(RealHandle, geometry.X, geometry.Y, geometry.Width, geometry.Height);
225 /// Sets the source file from where an image object must fetch the real image data (it may be an Eet file, besides pure image ones).
227 /// <param name="file">The image file path.</param>
228 /// <param name="key">The image key in file (if its an Eet one), otherwise set null.</param>
229 /// <since_tizen> preview </since_tizen>
230 public void SetFile(string file, string key)
232 Interop.Evas.evas_object_image_file_set(RealHandle, file, key);
236 /// Sets the data for an image from the memory to be loaded.
238 /// <param name="stream">memory stream</param>
239 /// <since_tizen> preview </since_tizen>
240 public void SetStream(Stream stream)
243 throw new ArgumentNullException("stream");
245 MemoryStream memstream = new MemoryStream();
246 stream.CopyTo(memstream);
249 byte[] dataArr = memstream.ToArray();
250 fixed (byte* data = &dataArr[0])
252 Interop.Evas.evas_object_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
259 /// Sets the source object on an image object to be used as a proxy.
261 /// <param name="source">The proxy (image) object.</param>
262 /// <returns>true if the source object is set successfully, otherwise false on error.</returns>
263 /// <since_tizen> preview </since_tizen>
264 public bool SetSource(EvasObject source)
268 result = Interop.Evas.evas_object_image_source_set(RealHandle, IntPtr.Zero);
270 result = result && Interop.Evas.evas_object_image_source_set(RealHandle, source.Handle);
275 /// Set the native surface of a given image of the canvas.
277 /// <param name="surface">The surface.</param>
278 /// <since_tizen> preview </since_tizen>
279 [EditorBrowsable(EditorBrowsableState.Never)]
280 public void SetNativeSurface(IntPtr surface)
282 Interop.Evas.evas_object_image_native_surface_set(RealHandle, surface);
286 /// Sets the dimensions for an image object's border, a region which is not scaled together with its center ever.
288 /// <param name="left">The border's left width.</param>
289 /// <param name="right">The border's right width.</param>
290 /// <param name="top">The border's top width.</param>
291 /// <param name="bottom">The border's bottom width.</param>
292 /// <since_tizen> preview </since_tizen>
293 public void SetBorder(int left, int right, int top, int bottom)
295 Interop.Evas.evas_object_image_border_set(RealHandle, left, right, top, bottom);
299 /// Save the given image object's contents to an (image) file.
301 /// The extension suffix on file will determine which saver module Evas is to use when saving, thus the final file's format. If the file supports multiple data stored in it (Eet ones), you can specify the key to be used as the index of the image in it.
303 /// You can specify some flags when saving the image.Currently acceptable flags are quality and compress.Eg.: "quality=100 compress=9"
305 /// <param name="file">The filename to be used to save the image (extension obligatory).</param>
306 /// <param name="key">The image key in the file (if an Eet one), or null, otherwise.</param>
307 /// <param name="flags">String containing the flags to be used (null for none).</param>
308 public void Save(string file, string key, string flags)
310 Interop.Evas.evas_object_image_save(RealHandle, file, key, flags);
314 /// Sets the content at a part of a given container widget.
316 /// <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>
317 /// <returns>The new object, otherwise null if it cannot be created.</returns>
318 /// <since_tizen> preview </since_tizen>
319 protected override IntPtr CreateHandle(EvasObject parent)
321 return _handle != IntPtr.Zero ? _handle : Interop.Evas.evas_object_image_add(Interop.Evas.evas_object_evas_get(parent.Handle));