[NUI][TEST] add sample to use native image
authortscholb <scholb.kim@samsung.com>
Thu, 26 May 2022 06:35:57 +0000 (15:35 +0900)
committerSeoyeon2Kim <34738918+Seoyeon2Kim@users.noreply.github.com>
Fri, 27 May 2022 06:15:42 +0000 (15:15 +0900)
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/NativeImageSourceTest.cs [new file with mode: 0644]

diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/NativeImageSourceTest.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/NativeImageSourceTest.cs
new file mode 100644 (file)
index 0000000..09d654c
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright(c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI.Samples
+{
+    using log = Tizen.Log;
+    public class NativeImageSourceSample : IExample
+    {
+        private const string tag = "NUITEST";
+        private Window mainWin;
+        private ImageView imageView;
+        const int imageWidth = 300;
+        const int imageHeight = 300;
+
+        public void Activate()
+        {
+            Initialize();
+        }
+
+        public void Deactivate()
+        {
+        }
+
+        private void Initialize()
+        {
+            mainWin = NUIApplication.GetDefaultWindow();
+            mainWin.BackgroundColor = Color.White;
+            Size2D windowSize = new Size2D(mainWin.Size.Width,mainWin.Size.Height);
+
+            NativeImageSource source = new NativeImageSource((uint)windowSize.Width, (uint)windowSize.Height, NativeImageSource.ColorDepth.Default);
+            var url = source.GenerateUrl();
+
+            int bufferWidth = 0;
+            int bufferHeight = 0;
+            int bufferStride = 0;
+            var buffer = source.AcquireBuffer(ref bufferWidth, ref bufferHeight, ref bufferStride); 
+            uint size = (uint) bufferWidth * (uint) bufferHeight * 4;
+            unsafe
+            {
+                byte* ptrData = (byte*) buffer.ToPointer();
+                for(int i=0; i< size; i+=4)
+                {
+                    ptrData[i] = 0;
+                    ptrData[i+1] = 255;
+                    ptrData[i+2] = 0;
+                    ptrData[i+3] = 255;
+                }
+            }
+
+            imageView = new ImageView(url.ToString());
+            imageView.Size2D = new Size2D( imageWidth, imageHeight);
+            mainWin.Add(imageView);
+        }
+    }
+}