Exemplo n.º 1
0
        static void Main()
        {
            // Set Logger
            ULPlatform.SetLogger(new ULLogger()
            {
                LogMessage = (level, message) =>
                {
                    Console.WriteLine($"({level}): {message}");
                }
            });

            // Set Font Loader
            AppCoreMethods.ulEnablePlatformFontLoader();

            // Set filesystem (Ultralight requires "resources/icudt67l.dat", and probably cacert.pem too)
            AppCoreMethods.ulEnablePlatformFileSystem(Path.GetDirectoryName(typeof(Program).Assembly.Location));

            // Create config, used for specifying resources folder (used for URL loading)
            ULConfig config = new();

            // Create Renderer
            Renderer renderer = new(config);

            // Create View
            View view = new(renderer, 512, 512);

            // Load URL

            bool loaded = false;

            view.SetFinishLoadingCallback((user_data, caller, frame_id, is_main_frame, url) =>
            {
                loaded = true;
            });

            view.URL = "https://github.com";             // Requires "UltralightNet.Resources"

            // Update Renderer until page is loaded
            while (!loaded)
            {
                renderer.Update();
                // sleep | give ultralight time to process network etc.
                Thread.Sleep(10);
            }

            // Render
            renderer.Render();

            // Get Surface
            ULSurface surface = view.Surface;

            // Get Bitmap
            ULBitmap bitmap = surface.Bitmap;

            // Swap Red and Blue channels
            bitmap.SwapRedBlueChannels();

            // save bitmap to png file
            bitmap.WritePng("./github.png");
        }
Exemplo n.º 2
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (renderer is null)
            {
                return;
            }

            renderer.Update();
            renderer.Render();

            ULBitmap bitmap = view.Surface.Bitmap;

            bitmap.WritePng("te.png");

            IntPtr pixels = bitmap.LockPixels();

            BitmapSource bitmapSource = BitmapSource.Create((int)bitmap.Width, (int)bitmap.Height, 1, 1, PixelFormats.Bgra32, BitmapPalettes.WebPaletteTransparent, pixels, (int)bitmap.Size, (int)bitmap.RowBytes);

            imageWPF.Source = bitmapSource;

            bitmap.UnlockPixels();
        }