Esempio n. 1
0
        async void mainCanvas_CreateResources(Microsoft.Graphics.Canvas.CanvasControl sender, object args)
        {
            m_isResourceLoadingDone = false;

            // WIN2D: resource loading from WinRT types including StorageFile and IRAS
            m_sourceBitmap = await CanvasBitmap.LoadAsync(sender, "Chrysanthemum.jpg");
            var sourceFile = await Package.Current.InstalledLocation.GetFileAsync("Chrysanthemum.jpg");

            // Win2D: because we can't lock/read pixels we rely on BitmapDecoder
            var stream = await sourceFile.OpenReadAsync();
            var decoder = await BitmapDecoder.CreateAsync(stream);

            // Technically these should always be identical to m_sourceBitmap.SizeInPixels;
            m_pixelArrayHeight = decoder.PixelHeight;
            m_pixelArrayWidth = decoder.PixelWidth;
            var pixelProvider = await decoder.GetPixelDataAsync(
                BitmapPixelFormat.Bgra8,
                BitmapAlphaMode.Premultiplied,
                new BitmapTransform(),
                ExifOrientationMode.IgnoreExifOrientation, // Must do this.
                ColorManagementMode.ColorManageToSRgb
                );

            m_pixelArray = pixelProvider.DetachPixelData();

            m_targetBitmap = new CanvasRenderTarget(sender, new Size(m_pixelArrayWidth, m_pixelArrayHeight));

            m_rnd = new Random();

            m_isResourceLoadingDone = true;

            mainCanvas.Invalidate();
        }
Esempio n. 2
0
 public async Task LoadSurfaceAsync(ICanvasResourceCreator creator, IRandomAccessStream stream)
 {
     tempSurface = await CanvasBitmap.LoadAsync(creator, stream);
     bound = tempSurface.Bounds;
     center = tempSurface.Size.ToVector2() / 2;
     blur.Source = tempSurface;
 }
Esempio n. 3
0
        public SpriteSheet(CanvasBitmap bitmap, Vector2 spriteSize, Vector2 origin)
        {
            this.bitmap = bitmap;
            SpriteSize = spriteSize;
            this.origin = origin;

            spritesPerRow = (int)(bitmap.Size.Width / spriteSize.X);
        }
Esempio n. 4
0
 public void CacheImage(string path, CanvasBitmap bi)
 {
     if (_enableImageCache
         && !_biCache.ContainsKey(path))
     {
         _biCache[path] = bi;
     }
 }
Esempio n. 5
0
 public void Process(CanvasBitmap input, CanvasRenderTarget output, TimeSpan time)
 {
     using (CanvasDrawingSession session = output.CreateDrawingSession())
     {
         session.DrawImage(input);
         session.DrawText("Canvas Effect test", 0f, 0f, Colors.Red);
     }
 }
Esempio n. 6
0
        private void Canvas_CreateResources(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
        {
            // Create instance of radial gradient brush; the center will be transparent and the extremes opaque black.
            radialBrush = new CanvasRadialGradientBrush(sender, Colors.Transparent, Colors.Black);

            // Load image to draw.
            args.TrackAsyncAction(Task.Run(async () =>
            {
                image = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///SpotlightImage.png"));
            }).AsAsyncAction());
        }
Esempio n. 7
0
 internal virtual void drawImage(CanvasBitmap canvasBitmap, int x, int y)
 {
     if (isMutable())
     {
         graphics.DrawImage(image2Premultiply(canvasBitmap), x, y);
     }
     else
     {
         graphics.DrawImage(canvasBitmap, x, y);
     }
 }
Esempio n. 8
0
        async Task Canvas_CreateResourcesAsync(CanvasControl sender)
        {
            bitmap = await CanvasBitmap.LoadAsync(sender, "imageTiger.jpg");

            redBrush   = CreateGradientBrush(sender, 255, 0, 0);
            greenBrush = CreateGradientBrush(sender, 0, 255, 0);
            blueBrush  = CreateGradientBrush(sender, 0, 0, 255);

            brightnessEffect = new BrightnessEffect  { Source = bitmap };
            saturationEffect = new SaturationEffect  { Source = brightnessEffect };
            hueEffect        = new HueRotationEffect { Source = saturationEffect };
        }
Esempio n. 9
0
 public void Process(CanvasBitmap input, CanvasRenderTarget output, TimeSpan time)
 {
     using (CanvasDrawingSession session = output.CreateDrawingSession())
     {
         session.DrawImage(input);
         session.FillCircle(
             (float)input.Bounds.Width / 2,
             (float)input.Bounds.Height / 2,
             (float)(Math.Min(input.Bounds.Width, input.Bounds.Height) / 2 * Math.Cos(2 * Math.PI * time.TotalSeconds)),
             Colors.Aqua
             );
     }
 }
Esempio n. 10
0
        private async Task loadBitmapImage(StorageFile sourceFile)
        {
            using (var sourceStream = await sourceFile.OpenAsync(FileAccessMode.Read))
            {
                //resize if needed
                if (useLogicChk.IsChecked.HasValue && !useLogicChk.IsChecked.Value)
                {
                    var scale = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
                    if (scale > 1)
                    {
                        maxImageSize = baseImageSize / scale;
                        canvas.Height = maxImageSize;
                        canvas.Width = maxImageSize;
                    }
                }

                //load image
                bitmapImg = await CanvasBitmap.LoadAsync(canvas, sourceStream);
                bitmapRect = new Rect();

                //determine width and height
                var width = bitmapImg.Size.Width;
                var height = bitmapImg.Size.Height;
                if (width > height)
                {
                    bitmapRect.Width = Math.Round(width * maxImageSize / height);
                    bitmapRect.Height = maxImageSize;
                    bitmapRect.X = -((bitmapRect.Width - bitmapRect.Height) / 2);
                    bitmapRect.Y = 0;
                }
                else if (height > width)
                {
                    bitmapRect.Width = maxImageSize;
                    bitmapRect.Height = Math.Round(height * maxImageSize / width);
                    bitmapRect.X = 0;
                    bitmapRect.Y = -((bitmapRect.Height - bitmapRect.Width) / 2);
                }
                else
                {
                    bitmapRect.Width = maxImageSize;
                    bitmapRect.Height = maxImageSize;
                    bitmapRect.X = 0;
                    bitmapRect.Y = 0;
                }

                //force canvas to redraw
                canvas.Invalidate();
            }

        }
Esempio n. 11
0
        private void BackgroundCanvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
        {
            args.TrackAsyncAction(Task.Run(async () =>
            {
                // Load the background image and create an image brush from it
                this.backgroundImage = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///Background.jpg"));
                this.backgroundBrush = new CanvasImageBrush(sender, this.backgroundImage);

                // Set the brush's edge behaviour to wrap, so the image repeats if the drawn region is too big
                this.backgroundBrush.ExtendX = this.backgroundBrush.ExtendY = CanvasEdgeBehavior.Wrap;

                this.resourcesLoaded = true;
            }).AsAsyncAction());
        }
Esempio n. 12
0
        async Task Canvas_CreateResourcesAsync(CanvasAnimatedControl sender)
        {
            bitmapTiger = await CanvasBitmap.LoadAsync(sender, "imageTiger.jpg");
            bitmapSize = bitmapTiger.Size.ToVector2();

            // The Dissolve shader has two input textures:
            //
            //  - The first is an image that will be dissolved away to nothing.
            //
            //  - The second is a dissolve mask whose red channel controls the order in which pixels
            //    of the first image disappear as the dissolveAmount property is animated.
            //
            // This example selects different dissolve masks depending on the CurrentEffect.

            dissolveEffect = new PixelShaderEffect(await Utils.ReadAllBytes("Shaders/Dissolve.bin"))
            {
                Source1 = bitmapTiger
            };

            // The Ripples shader has no input textures.
            // It generates an animatable series of concentric circles.
            // This is used as a mask input to the dissolveEffect.
            rippleEffect = new PixelShaderEffect(await Utils.ReadAllBytes("Shaders/Ripples.bin"));

            rippleEffect.Properties["frequency"] = 0.15f;
            rippleEffect.Properties["dpi"] = sender.Dpi;
#if WINDOWS_UWP
            rippleEffect.Properties["center"] = bitmapSize / 3;
#else
            rippleEffect.Properties["center"] = (Microsoft.Graphics.Canvas.Numerics.Vector2)(bitmapSize / 3);

            // When compiling for Windows 8.1, we must explicitly convert vector and matrix values
            // from System.Numerics to their Microsoft.Graphics.Canvas.Numerics equivalents before
            // passing them to PixelShaderEffect.Properties. This is not neccessary when targetting
            // UWP, which handles the conversion automatically. For more info, see the article:
            // http://blogs.msdn.com/b/win2d/archive/2015/06/02/winrt-vector-and-matrix-types-in-windows-10.aspx
#endif

            // Create other dissolve mask images.
            CreateTurbulence();
            CreateLinearGradient(sender);
            CreateRadialGradient(sender);
        }
Esempio n. 13
0
        public SpriteSheet(CanvasBitmap image, IEnumerable<string> names, OB.Point size, int padding)
        {
            _image = image;
            _size = size;
            _padding = padding;

            _spriteSize = new OB.Point(
                ((int)image.SizeInPixels.Width - size.X * padding) / size.X,
                ((int)image.SizeInPixels.Height - size.Y * padding) / size.Y);

            var i = 0;

            foreach (var name in names)
            {
                if (!string.IsNullOrWhiteSpace(name))
                {
                    var x = i % size.X;
                    var y = i / size.X;
                    _names[name] = new OB.Point(x, y);
                }
                i++;
            }
        }
Esempio n. 14
0
        CompositionDrawingSurface ApplyBlurEffect(CanvasBitmap bitmap, Windows.UI.Composition.CompositionGraphicsDevice device, Size sizeTarget)
        {
            GaussianBlurEffect blurEffect = new GaussianBlurEffect()
            {
                Source = bitmap,
                BlurAmount = 20.0f
            };

            float fDownsample = .3f;
            Size sizeSource = bitmap.Size;
            if (sizeTarget == Size.Empty)
            {
                sizeTarget = sizeSource;
            }

            sizeTarget = new Size(sizeTarget.Width * fDownsample, sizeTarget.Height * fDownsample);
            CompositionDrawingSurface blurSurface = device.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);
            using (var ds = CanvasComposition.CreateDrawingSession(blurSurface))
            {
                Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height);
                ds.Clear(Windows.UI.Color.FromArgb(255, 255, 255, 255));
                ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height));
            }

            return blurSurface;
        }
Esempio n. 15
0
 async Task canvasControl_CreateResourcesAsync(CanvasControl sender)
 {
     tiger = await CanvasBitmap.LoadAsync(sender, "imageTiger.jpg");
 }
Esempio n. 16
0
 private void CanvasControl_CreateResources(Win2DCanvas.UI.Xaml.CanvasControl sender, Win2DCanvas.UI.CanvasCreateResourcesEventArgs args)
 {
     _win2dBitmap = Win2DCanvas.CanvasBitmap.CreateFromColors(sender, _bitmapColors, SIZE, SIZE);
 }
Esempio n. 17
0
        async Task Canvas_CreateResourcesAsync(CanvasControl sender)
        {
            bitmapTiger = await CanvasBitmap.LoadAsync(sender, "imageTiger.jpg");

            CreateEffect();
        }
Esempio n. 18
0
        async Task DriveCanvas_CreateResourcesAsync(CanvasControl sender)
        {
            joystickBitmap = await CanvasBitmap.LoadAsync(sender, "Assets/Joystick.png");

            joystickCanvasSize = new Size(sender.ActualWidth, sender.ActualHeight);

            joystickDrawRect = new Rect(0, 0, JOYSTICK_HALF_SIZE*2, JOYSTICK_HALF_SIZE*2);
            joystickDirection = new Vector2();

            UpdateJoystick(sender, joystickCanvasSize.Width / 2, joystickCanvasSize.Height / 2, true);

            joystickTimer = new Timer(MipMove, this, MOVE_TICK_INTERVAL_IN_MS, Timeout.Infinite);
        }
Esempio n. 19
0
        private async void BrowseBaseButton_Click(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();
            picker.FileTypeFilter.Add(".jpg");
            var file = await picker.PickSingleFileAsync();
            if (file == null) return;
            baseFile = file;
            baseCanvas = await CanvasBitmap.LoadAsync(canvasOfAvaga.Device, await baseFile.OpenReadAsync(), 96, CanvasAlphaMode.Premultiplied);
            canvasOfAvaga.Invalidate();

            ACTHEIGHT = baseCanvas.SizeInPixels.Height;
            ACTWIDTH = baseCanvas.SizeInPixels.Width;
        }
Esempio n. 20
0
 private async void BrowseWatermark_Click(object sender, RoutedEventArgs e)
 {
     var picker = new FileOpenPicker();
     picker.FileTypeFilter.Add(".png");
     var file = await picker.PickSingleFileAsync();
     if (file == null) return;
     watermarkFile = file;
     watermarkCanvas = await CanvasBitmap.LoadAsync(canvasOfAvaga.Device, await watermarkFile.OpenReadAsync(), 96, CanvasAlphaMode.Premultiplied);
     canvasOfAvaga.Invalidate();
     
 }
 private async Task Canvas_CreateResourcesAsync(CanvasControl sender, CanvasCreateResourcesEventArgs args)
 {
     _bitmap = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///Assets/menu_background.jpg"));
 }
        async Task CreateResourcesAsync(CanvasControl sender)
        {
            // give it a little bit delay to ensure the image is load, ideally you want to Image.ImageOpened event instead
            await Task.Delay(200);

            using (var stream = new InMemoryRandomAccessStream())
            {
                // get the stream from the background image
                var target = new RenderTargetBitmap();
                await target.RenderAsync(this.Image2);

                var pixelBuffer = await target.GetPixelsAsync();
                var pixels = pixelBuffer.ToArray();

                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream);
                encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)target.PixelWidth, (uint)target.PixelHeight, 96, 96, pixels);

                await encoder.FlushAsync();
                stream.Seek(0);

                // load the stream into our bitmap
                _bitmap = await CanvasBitmap.LoadAsync(sender, stream);
            }
        }
Esempio n. 23
0
 public void SetBitmap(CanvasBitmap bitmap)
 {
     resourceBitmap = bitmap;
 }
Esempio n. 24
0
 // 载入纹理
 public virtual async Task LoadSurfaceAsync(ICanvasResourceCreator resourceCreator)
 {
     if (surfaceLoaded)
         return;
     bitmap = await CanvasBitmap.LoadAsync(resourceCreator, bitmapFilename);
     surfaceLoaded = true;
 }
Esempio n. 25
0
        // Loads the bitmap that will be used to draw this particle system.
        public virtual async Task CreateResourcesAsync(ICanvasResourceCreator resourceCreator)
        {
            bitmap = await CanvasBitmap.LoadAsync(resourceCreator, bitmapFilename);

            bitmapCenter = bitmap.Size.ToVector2() / 2;
            bitmapBounds = bitmap.Bounds;
        }
Esempio n. 26
0
 internal virtual void drawImage(CanvasBitmap canvasBitmap, int x, int y, int w, int h)
 {
     ScaleEffect scale = new ScaleEffect()
     {
         Source = canvasBitmap,
         Scale = new Vector2()
         {
             X = ((float)w) / canvasBitmap.SizeInPixels.Width,
             Y = ((float)h) / canvasBitmap.SizeInPixels.Height
         }
     };
     if (isMutable())
     {
         graphics.DrawImage(image2Premultiply(scale), x, y);
     }
     else
     {
         graphics.DrawImage(scale, x, y);
     }
 }
Esempio n. 27
0
 internal virtual void tileImage(CanvasBitmap canvasBitmap, int x, int y, int w, int h)
 {
     CanvasImageBrush brush = new CanvasImageBrush(graphics.Device, canvasBitmap);
     brush.ExtendX = CanvasEdgeBehavior.Wrap;
     brush.ExtendY = CanvasEdgeBehavior.Wrap;
     System.Numerics.Matrix3x2 currentTransform = graphics.Transform;
     graphics.Transform = System.Numerics.Matrix3x2.CreateTranslation(x, y);
     graphics.FillRectangle(0, 0, w, h, brush);
     graphics.Transform = currentTransform;
 }
Esempio n. 28
0
            void DoTest(float opacity, CanvasBitmap source, CanvasRenderTarget target)
            {
                using (var ds = target.CreateDrawingSession())
                {
                    ds.FillRectangle(target.Bounds, fillPattern);

                    var leftHalf = source.Bounds;
                    leftHalf.Width /= 2;

                    var rightHalf = source.Bounds;
                    rightHalf.Width /= 2;
                    rightHalf.X += rightHalf.Width;

                    // This version calls D2D DrawBitmap
                    ds.DrawImage(source, 0, 0, leftHalf, opacity, CanvasImageInterpolation.Linear);

                    // This version calls D2D DrawImage with emulated opacity
                    ds.DrawImage(source, (float)rightHalf.X, 0, rightHalf, opacity, CanvasImageInterpolation.Cubic);

                    ds.Antialiasing = CanvasAntialiasing.Aliased;
                    ds.DrawLine((float)rightHalf.X, 0, (float)rightHalf.X, (float)rightHalf.Height, Colors.Black, 1, hairline);
                }
            }
Esempio n. 29
0
 public DestRectDemo(DrawImageEmulations example, CanvasControl sender)
 {
     fillPattern = example.checkedFillPattern;
     sourceBitmap = example.tiger;
     sourceEffect = new HueRotationEffect()
     {
         Source = sourceBitmap,
         Angle = 1
     };
 }
Esempio n. 30
0
            public OffsetDemo(DrawImageEmulations example, CanvasControl sender)
            {
                fillPattern = example.checkedFillPattern;

                var rt = new CanvasRenderTarget(sender, (float)example.tiger.Size.Width, (float)example.tiger.Size.Height, sender.Dpi / 3);
                using (var ds = rt.CreateDrawingSession())
                {
                    ds.DrawImage(example.tiger, rt.Bounds);
                }
                sourceBitmap = rt;

                sourceEffect = new HueRotationEffect()
                {
                    Source = sourceBitmap,
                    Angle = 1
                };

                showSourceRectRT = new CanvasRenderTarget(sender, (float)rt.Size.Width, (float)rt.Size.Height, rt.Dpi);
            }
Esempio n. 31
-1
        public BitmapSourceOption NextBitmapSourceOption { get; set; } // databinded

        async Task LoadBitmaps(CanvasControl sender)
        {   
            var newTestBitmaps = new CanvasBitmap[fileNames.Length];

            for (int i = 0; i < fileNames.Length; i++)
            {
                Package package = Package.Current;
                StorageFolder installedLocation = package.InstalledLocation;
                string pathName = installedLocation.Path + "\\" + "BitmapOrientation" + "\\" + fileNames[i];

                if (currentBitmapSourceOption == BitmapSourceOption.FromStream)
                {
                    StorageFile storageFile = await StorageFile.GetFileFromPathAsync(pathName);
                    using (IRandomAccessStreamWithContentType stream = await storageFile.OpenReadAsync())
                    {
                        newTestBitmaps[i] = await CanvasBitmap.LoadAsync(sender, stream);
                    }
                }
                else
                {
                    newTestBitmaps[i] = await CanvasBitmap.LoadAsync(sender, pathName);
                }
            }

            testBitmaps = newTestBitmaps;
        }