示例#1
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            // Read image pixels
            var          path   = Path.Combine(Environment.CurrentDirectory, @"..\..\Examples\UsingRenderContextAPI\Resources", "TestImage.jpg");
            BitmapSource bitmap = new BitmapImage(new Uri(path));

            _pixels = new int[bitmap.PixelWidth * bitmap.PixelHeight];
            bitmap.CopyPixels(_pixels, bitmap.PixelWidth * 4, 0);

            // Create a Texture
            using (var rc = RenderSurface.GetRenderContext())
            {
                // Texture creation is very consuming, so recreate it as seldom as possible
                if (_texture == null)
                {
                    _texture.SafeDispose();
                    _texture = rc.CreateTexture(bitmap.PixelWidth, bitmap.PixelHeight);
                }
            }

            // Draw a Texture
            RenderTexture();
        }