Ejemplo 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");
        }
Ejemplo 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();
        }
Ejemplo n.º 3
0
 public static extern bool ulBitmapWritePNG(ULBitmap bitmap, [MarshalAs(UnmanagedType.LPStr)] string path);
Ejemplo n.º 4
0
 public static extern void ulBitmapErase(ULBitmap bitmap);
Ejemplo n.º 5
0
 public static extern bool ulBitmapIsEmpty(ULBitmap bitmap);
Ejemplo n.º 6
0
 public static extern IntPtr ulBitmapRawPixels(ULBitmap bitmap);
Ejemplo n.º 7
0
 public static extern void ulBitmapUnlockPixels(ULBitmap bitmap);
Ejemplo n.º 8
0
 public static extern bool ulBitmapOwnsPixels(ULBitmap bitmap);
Ejemplo n.º 9
0
 public static extern UIntPtr ulBitmapGetSize(ULBitmap bitmap);
Ejemplo n.º 10
0
 public static extern uint ulBitmapGetRowBytes(ULBitmap bitmap);
Ejemplo n.º 11
0
 public static extern uint ulBitmapGetBpp(ULBitmap bitmap);
Ejemplo n.º 12
0
 public static extern ULBitmapFormat ulBitmapGetFormat(ULBitmap bitmap);
Ejemplo n.º 13
0
 public static extern uint ulBitmapGetHeight(ULBitmap bitmap);
Ejemplo n.º 14
0
 public static extern uint ulBitmapGetWidth(ULBitmap bitmap);
Ejemplo n.º 15
0
 public static extern void ulDestroyBitmap(ULBitmap bitmap);
Ejemplo n.º 16
0
 public static extern ULBitmap ulCreateBitmapFromCopy(ULBitmap existing_bitmap);