Ejemplo n.º 1
0
        public IActionResult Index()
        {
            if (HybridSupport.IsElectronActive)
            {
                Electron.IpcMain.On("copy-to", (text) =>
                {
                    Electron.Clipboard.WriteText(text.ToString());
                });

                Electron.IpcMain.On("paste-to", async(text) =>
                {
                    Electron.Clipboard.WriteText(text.ToString());
                    string pasteText = await Electron.Clipboard.ReadTextAsync();

                    var mainWindow = Electron.WindowManager.BrowserWindows.First();
                    Electron.IpcMain.Send(mainWindow, "paste-from", pasteText);
                });

                Electron.IpcMain.On("copy-image-to", (test) =>
                {
                    var nativeImage = NativeImage.CreateFromDataURL(test.ToString());
                    Electron.Clipboard.WriteImage(nativeImage);
                });

                Electron.IpcMain.On("paste-image-to", async test =>
                {
                    var nativeImage = await Electron.Clipboard.ReadImageAsync();
                    var mainWindow  = Electron.WindowManager.BrowserWindows.First();
                    Electron.IpcMain.Send(mainWindow, "paste-image-from", JsonConvert.SerializeObject(nativeImage));
                });
            }

            return(View());
        }
Ejemplo n.º 2
0
 public NativeImage(NativeImage handle) : this(NDalicPINVOKE.new_NativeImage__SWIG_1(NativeImage.getCPtr(handle)), true)
 {
     if (NDalicPINVOKE.SWIGPendingException.Pending)
     {
         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 3
0
        private void SetAdUI(NativeAdV2 nativeAd)
        {
            if (nativeAd.AdIcon != null)
            {
                AdIconImage2.Source = nativeAd.AdIcon.Source;
            }

            // Show the ad title.
            TitleTextBlock.Text = nativeAd.Title;

            if (nativeAd.MainImages.Count > 0)
            {
                NativeImage mainImage   = nativeAd.MainImages[0];
                BitmapImage bitmapImage = new BitmapImage
                {
                    UriSource = new Uri(mainImage.Url)
                };
                AdIconImage.Source = bitmapImage;

                AdIconImage.Visibility = Visibility.Visible;
            }

            // Add the call to action string to the button.
            if (!string.IsNullOrEmpty(nativeAd.CallToActionText))
            {
                CallToActionButton.Content    = nativeAd.CallToActionText;
                CallToActionButton.Visibility = Visibility.Visible;
            }
            nativeAd.RegisterAdContainer(NativeAdContainer);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 运行检测算法,在给定图像中检测关联图案的角点。
        /// </summary>
        /// <param name="img">检测算法的目标图像</param>
        /// <param name="drawLayer">用以绘制检测结果或其他信息的绘制图层</param>
        /// <param name="isDebug">是否开启调试模式(开启将会显示额外的调试窗口)</param>
        /// <returns>检测结果,<c>null</c>表示未检测到有效的关联图案</returns>
        /// <remarks>返回的角点坐标中<see cref="float.NaN"/>表示未检测到图案中对应位置的角点</remarks>
        public Array <Vector2> Run(NativeImage img, NativeImage drawLayer, bool isDebug = false)
        {
            var results = new Array <Vector2> (pattern.nCorners);

            return(Plugin.Detector_run(this, img, results, drawLayer, isDebug) ?
                   results :
                   null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 运行检测算法,在给定画面帧中检测关联图案的角点。
        /// </summary>
        /// <param name="frame">相机的画面帧对象</param>
        /// <param name="drawLayer">用以绘制检测结果或其他信息的绘制图层</param>
        /// <param name="isDebug">是否开启调试模式(开启将会显示额外的调试窗口)</param>
        /// <returns>检测结果,<c>null</c>表示未检测到有效的关联图案</returns>
        /// <remarks>返回的角点坐标中<see cref="float.NaN"/>表示未检测到图案中对应位置的角点</remarks>
        public Array <Vector2> Run(Frame frame, NativeImage drawLayer, bool isDebug = false)
        {
            var results = new Array <Vector2> (pattern.nCorners);

            return(Plugin.Detector_run2(this, frame, frame.isUndistorted, results, drawLayer,
                                        isDebug) ?
                   results :
                   null);
        }
        public NativeAdData()
        {
            myNativeAdsManager = new NativeAdsManagerV2(myAppId, myAdUnitId);
            //this might cause memory leak because the event is not being unSubscribed.
            //Though not sure how to work around this.
            myNativeAdsManager.AdReady += (s, e) =>
            {
                nativeAd = e.NativeAd;

                // Show the ad icon.
                if (nativeAd.AdIcon != null)
                {
                    AdIcon = nativeAd.AdIcon.Source;
                }
                //Show the ad title.
                Title = nativeAd.Title;

                // Show the ad description.
                //if (!string.IsNullOrEmpty(nativeAd.Description))
                //{
                //    Description = nativeAd.Description;
                //}

                // Display the first main image for the ad. Note that the service
                // might provide multiple main images.
                if (nativeAd.MainImages.Count > 0)
                {
                    NativeImage mainImage   = nativeAd.MainImages[0];
                    BitmapImage bitmapImage = new BitmapImage
                    {
                        UriSource = new Uri(mainImage.Url)
                    };
                    MainImageUrl = bitmapImage;
                }

                // Add the call to action string to the button.
                //if (!string.IsNullOrEmpty(nativeAd.CallToActionText))
                //{
                //    CallToAction = nativeAd.CallToActionText;
                //}
                // Show the ad sponsored by value.
                //if (!string.IsNullOrEmpty(nativeAd.SponsoredBy))
                //{
                //    SponsoredBy = nativeAd.SponsoredBy;
                //}
                // Show the icon image for the ad.
                //if (nativeAd.IconImage != null)
                //{
                //    BitmapImage bitmapImage = new BitmapImage
                //    {
                //        UriSource = new Uri(nativeAd.IconImage.Url)
                //    };
                //}
                nativeAd?.RegisterAdContainer(parent);
            };
            myNativeAdsManager.ErrorOccurred += (s, e) => Title = "ErrorAds".GetLocalized();
        }
Ejemplo n.º 7
0
        public new static NativeImage DownCast(BaseHandle handle)
        {
            NativeImage ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as NativeImage;

            if (NDalicPINVOKE.SWIGPendingException.Pending)
            {
                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 8
0
        public NativeImage Assign(NativeImage rhs)
        {
            NativeImage ret = new NativeImage(NDalicPINVOKE.NativeImage_Assign(swigCPtr, NativeImage.getCPtr(rhs)), false);

            if (NDalicPINVOKE.SWIGPendingException.Pending)
            {
                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// See base docs.
        /// </summary>
        /// <param name="imageFormat"></param>
        /// <returns></returns>
        public override byte[] GetImageBytes(VrsDrawing.ImageFormat imageFormat)
        {
            using (var memoryStream = new MemoryStream()) {
                GdiPlusLock.EnforceSingleThread(() => {
                    NativeImage.Save(
                        memoryStream,
                        Convert.ToSystemDrawingImageFormat(imageFormat)
                        );
                });

                return(memoryStream.ToArray());
            }
        }
Ejemplo n.º 10
0
        private List <NativeImage> GetNativeImages(List <ModuleInformation> modules)
        {
            List <NativeImage> nativeImages = new List <NativeImage>();

            foreach (var module in modules.Where(m => Path.GetFileName(m.Path) == Module))
            {
                NativeImage nativeImage = new NativeImage();
                nativeImage.ModuleInformation = module;
                nativeImage.DosHeader         = new Pointer <WinApi.IMAGE_DOS_HEADER>(ParentProcessId, ParentProcessHandle, module.BaseAdress, Marshal.SizeOf(typeof(WinApi.IMAGE_DOS_HEADER))).GetValue();
                nativeImage.NtHeader          = new Pointer <WinApi.IMAGE_NT_HEADERS>(ParentProcessId, ParentProcessHandle, module.BaseAdress + nativeImage.DosHeader.e_lfanew, Marshal.SizeOf(typeof(WinApi.IMAGE_NT_HEADERS))).GetValue();
                nativeImage.ExportDirectory   = new Pointer <WinApi.IMAGE_EXPORT_DIRECTORY>(ParentProcessId, ParentProcessHandle, module.BaseAdress + (int)nativeImage.NtHeader.OptionalHeader.ExportTable.VirtualAddress, Marshal.SizeOf(typeof(WinApi.IMAGE_EXPORT_DIRECTORY))).GetValue();

                nativeImages.Add(nativeImage);
            }
            return(nativeImages);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// See base docs.
        /// </summary>
        /// <returns></returns>
        public override VrsDrawing.IImage Clone()
        {
            VrsDrawing.IImage result = null;

            GdiPlusLock.EnforceSingleThread(() => {
                // GDI+ version of clone is a bit dodgy. We need to create a brand-new
                // copy of the image instead.
                if (NativeImage is Bitmap bitmap)
                {
                    result = new ImageWrapper(new Bitmap(bitmap));
                }
                else
                {
                    throw new InvalidOperationException($"Cannot clone {NativeImage.GetType().FullName} image objects");
                }
            });

            return(result);
        }
Ejemplo n.º 12
0
 public static extern void drawCircle(NativeImage img, Vector2 center, float radius,
                                      Color32 color, int thickness, int shift);
Ejemplo n.º 13
0
 public static extern void drawEllipse(NativeImage img, Vector2 center, Vector2 axes,
                                       double angle, double startAngle, double endAngle, Color32 color, int thickness,
                                       int shift);
Ejemplo n.º 14
0
 /// <summary>
 /// 绘制图案至给定的图像。
 /// </summary>
 /// <param name="img">用以绘制图案的图像</param>
 /// <param name="color">图案的前景色</param>
 /// <remarks>绘制的图案始终为黑色背景。</remarks>
 public void Draw(NativeImage img, Color32 color) => Plugin.Pattern_draw(this, img, color);
Ejemplo n.º 15
0
 /// <summary>
 /// 使用默认前景色(白色)绘制图案至给定的图像。
 /// </summary>
 /// <param name="img">用以绘制图案的图像</param>
 /// <remarks>绘制的图案始终为黑色背景。</remarks>
 /// <seealso cref="Draw(NativeImage,UnityEngine.Color32)"/>
 public void Draw(NativeImage img) => Plugin.Pattern_draw(this, img, Color.white);
Ejemplo n.º 16
0
 public static extern void drawLine(NativeImage img, Vector2 pt1, Vector2 pt2, Color32 color,
                                    int thickness, int shift);
Ejemplo n.º 17
0
 public static extern void drawText(NativeImage img, string text, Vector2Int org,
                                    Painter.Font fontFace, double fontScale, Color32 color, int thickness,
                                    [MarshalAs(UnmanagedType.I1)] bool bottomLeftOrigin, int shift);
Ejemplo n.º 18
0
 public static extern bool Detector_run(IntPtr p_inst, NativeImage img,
                                        Array <Vector2> resultsOut, NativeImage drawLayerOut,
                                        [MarshalAs(UnmanagedType.I1)] bool isDebug);
Ejemplo n.º 19
0
 public static extern bool Detector_run2(IntPtr p_inst, IntPtr p_frame,
                                         [MarshalAs(UnmanagedType.I1)] bool useUndistorted,
                                         Array <Vector2> resultsOut, NativeImage drawLayerOut,
                                         [MarshalAs(UnmanagedType.I1)] bool isDebug);
Ejemplo n.º 20
0
 public static extern void drawTriangle(NativeImage img, Vector2 pt, float r, float angle,
                                        Color32 color, int thickness, int shift);
Ejemplo n.º 21
0
 public static extern void Pattern_draw(IntPtr p_inst, NativeImage img, Color32 color);
Ejemplo n.º 22
0
 /// <summary>
 /// Writes an image to the clipboard.
 /// </summary>
 /// <param name="image"></param>
 /// <param name="type"></param>
 public void WriteImage(NativeImage image, string type = "")
 {
     BridgeConnector.Socket.Emit("clipboard-writeImage", JsonConvert.SerializeObject(image), type);
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Renders the current complete scene.
        /// </summary>
        private void Render()
        {
            try
            {
                if (_renderingSuspended)
                { // no rendering when rendering is suspended.
                    return;
                }

                if (_cacheRenderer.IsRunning)
                { // cancel previous render.
                    _cacheRenderer.CancelAndWait();
                }

                // make sure only on thread at the same time is using the renderer.
                lock (_cacheRenderer)
                {
                    this.Map.ViewChangedCancel();

                    // build the layers list.
                    var layers = new List <Layer>();
                    for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++)
                    { // get the layer.
                        if (this.Map[layerIdx].IsVisible)
                        {
                            layers.Add(this.Map[layerIdx]);
                        }
                    }

                    // add the internal layers.
                    layers.Add(_makerLayer);

                    if (this.SurfaceHeight == 0)
                    { // the surface has no height yet. Impossible to render like this.
                        return;
                    }

                    // get old image if available.
                    NativeImage image = null;
                    if (_offScreenBuffer != null)
                    { // get the native image from the off-screen buffer.
                        image = _offScreenBuffer.NativeImage as NativeImage;
                    }

                    // resize image if needed.
                    float sizeX = this.SurfaceWidth;
                    float sizeY = this.SurfaceHeight;
                    //if(this.MapAllowTilt)
                    //{ // when rotation is allowed make sure a square is rendered.
                    //    sizeX = System.Math.Max(this.SurfaceWidth, this.SurfaceHeight);
                    //    sizeY = System.Math.Max(this.SurfaceWidth, this.SurfaceHeight);
                    //}
                    // float size = System.Math.Max(this.SurfaceHeight, this.SurfaceWidth);
                    if (image == null ||
                        image.Image.Width != (int)(sizeX * _extra) ||
                        image.Image.Height != (int)(sizeY * _extra))
                    {     // create a bitmap and render there.
                        if (image != null)
                        { // make sure to dispose the old image.
                            image.Dispose();
                        }
                        image = new NativeImage(global::Android.Graphics.Bitmap.CreateBitmap((int)(sizeX * _extra),
                                                                                             (int)(sizeY * _extra),
                                                                                             global::Android.Graphics.Bitmap.Config.Argb8888));
                    }

                    // create and reset the canvas.
                    using (var canvas = new global::Android.Graphics.Canvas(image.Image))
                    {
                        canvas.DrawColor(new global::Android.Graphics.Color(
                                             SimpleColor.FromKnownColor(KnownColor.White).Value));

                        // create the view.
                        double[] sceneCenter     = this.Map.Projection.ToPixel(this.MapCenter.Latitude, this.MapCenter.Longitude);
                        float    mapZoom         = this.MapZoom;
                        float    sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

                        // create the view for this control.
                        float scaledNormalWidth  = image.Image.Width / _bufferFactor;
                        float scaledNormalHeight = image.Image.Height / _bufferFactor;
                        var   view = View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1],
                                                       scaledNormalWidth * _extra, scaledNormalHeight * _extra, sceneZoomFactor,
                                                       _invertX, _invertY, this.MapTilt);

                        long before = DateTime.Now.Ticks;

                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                        "Rendering Start");

                        // notify the map that the view has changed.
                        if (_previouslyChangedView == null ||
                            !_previouslyChangedView.Equals(view))
                        { // report change once!
                            var normalView = View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1],
                                                               scaledNormalWidth, scaledNormalHeight, sceneZoomFactor,
                                                               _invertX, _invertY, this.MapTilt);
                            this.Map.ViewChanged((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter,
                                                 normalView, view);
                            _previouslyChangedView = view;
                            long afterViewChanged = DateTime.Now.Ticks;
                            OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                            "View change took: {0}ms @ zoom level {1}",
                                                            (new TimeSpan(afterViewChanged - before).TotalMilliseconds), this.MapZoom);
                        }

                        // does the rendering.
                        bool complete = _cacheRenderer.Render(canvas, layers, view, (float)this.Map.Projection.ToZoomFactor(this.MapZoom));

                        long afterRendering = DateTime.Now.Ticks;
                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                                        "Rendering took: {0}ms @ zoom level {1} and {2}",
                                                        (new TimeSpan(afterRendering - before).TotalMilliseconds), this.MapZoom, this.MapCenter);
                        if (complete)
                        { // there was no cancellation, the rendering completely finished.
                            // add the result to the scene cache.
                            // add the newly rendered image again.
                            if (_offScreenBuffer == null)
                            { // create the offscreen buffer first.
                                _offScreenBuffer = new ImageTilted2D(view.Rectangle, image, float.MinValue, float.MaxValue);
                            }
                            else
                            { // augment the previous buffer.
                                _offScreenBuffer.Bounds      = view.Rectangle;
                                _offScreenBuffer.NativeImage = image;
                            }

                            var temp = _onScreenBuffer;
                            _onScreenBuffer  = _offScreenBuffer;
                            _offScreenBuffer = temp;
                        }

                        long after = DateTime.Now.Ticks;

                        if (complete)
                        { // report a successful render to listener.
                            _listener.NotifyRenderSuccess(view, mapZoom, (int)new TimeSpan(after - before).TotalMilliseconds);
                        }
                    }
                }

                // notify the the current surface of the new rendering.
                this.PostInvalidate();
            }
            catch (Exception ex)
            { // exceptions can be thrown when the mapview is disposed while rendering.
                // don't worry too much about these, the mapview is garbage anyway.
                OsmSharp.Logging.Log.TraceEvent("MapViewSurface", TraceEventType.Critical,
                                                string.Format("An unhandled exception occured:{0}", ex.ToString()));
            }
        }
Ejemplo n.º 24
0
 public static extern void drawMarkers(NativeImage img, Array <Vector2> pts,
                                       Painter.MarkerType type, int size, Color32 color, int thickness, int shift);
Ejemplo n.º 25
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(NativeImage obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Ejemplo n.º 26
0
 public static extern void drawPolyline(NativeImage img, Array <Vector2> points,
                                        Color32 color, int thickness, [MarshalAs(UnmanagedType.I1)] bool isConvexOrClosed,
                                        int shift);
Ejemplo n.º 27
0
 public static extern void drawRectangle(NativeImage img, Vector2 tl, Vector2 br, Color32 color,
                                         int thickness, int shift);
Ejemplo n.º 28
0
 public void Dispose()
 {
     NativeImage.Dispose();
 }
Ejemplo n.º 29
0
        //<AdReady>
        void MyNativeAd_AdReady(object sender, NativeAdReadyEventArgs e)
        {
            NativeAdV2 nativeAd = e.NativeAd;

            // Show the ad icon.
            if (nativeAd.AdIcon != null)
            {
                AdIconImage.Source = nativeAd.AdIcon.Source;

                // Adjust the Image control to the height and width of the
                // provided ad icon.
                AdIconImage.Height = nativeAd.AdIcon.Height;
                AdIconImage.Width  = nativeAd.AdIcon.Width;
            }

            // Show the ad title.
            TitleTextBlock.Text = nativeAd.Title;

            // Show the ad description.
            if (!string.IsNullOrEmpty(nativeAd.Description))
            {
                DescriptionTextBlock.Text       = nativeAd.Description;
                DescriptionTextBlock.Visibility = Visibility.Visible;
            }

            // Display the first main image for the ad. Note that the service
            // might provide multiple main images.
            if (nativeAd.MainImages.Count > 0)
            {
                NativeImage mainImage   = nativeAd.MainImages[0];
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.UriSource = new Uri(mainImage.Url);
                MainImageImage.Source = bitmapImage;

                // Adjust the Image control to the height and width of the
                // main image.
                MainImageImage.Height     = mainImage.Height;
                MainImageImage.Width      = mainImage.Width;
                MainImageImage.Visibility = Visibility.Visible;
            }

            // Add the call to action string to the button.
            if (!string.IsNullOrEmpty(nativeAd.CallToActionText))
            {
                CallToActionButton.Content    = nativeAd.CallToActionText;
                CallToActionButton.Visibility = Visibility.Visible;
            }

            // Show the ad sponsored by value.
            if (!string.IsNullOrEmpty(nativeAd.SponsoredBy))
            {
                SponsoredByTextBlock.Text       = nativeAd.SponsoredBy;
                SponsoredByTextBlock.Visibility = Visibility.Visible;
            }

            // Show the icon image for the ad.
            if (nativeAd.IconImage != null)
            {
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.UriSource = new Uri(nativeAd.IconImage.Url);
                IconImageImage.Source = bitmapImage;

                // Adjust the Image control to the height and width of the
                // icon image.
                IconImageImage.Height     = nativeAd.IconImage.Height;
                IconImageImage.Width      = nativeAd.IconImage.Width;
                IconImageImage.Visibility = Visibility.Visible;
            }

            // Register the container of the controls that display
            // the native ad elements for clicks/impressions.
            nativeAd.RegisterAdContainer(NativeAdContainer);
        }
Ejemplo n.º 30
0
 public static extern void drawFill(NativeImage img, Color32 background, int shift);