Beispiel #1
0
        public override void Render(DrawingContext context)
        {
            var source = Source;
            var mem    = new MemoryStream();

            Source.Save(mem);

            if (source != null && mem.Length > 0 && Bounds.Width > 0 && Bounds.Height > 0)
            {
                Rect viewPort   = new Rect(Bounds.Size);
                Size sourceSize = source.Size;

                Vector scale      = Stretch.CalculateScaling(Bounds.Size, sourceSize, StretchDirection);
                Size   scaledSize = sourceSize * scale;
                Rect   destRect   = viewPort
                                    .CenterRect(new Rect(scaledSize))
                                    .Intersect(viewPort);
                Rect sourceRect = new Rect(sourceSize)
                                  .CenterRect(new Rect(destRect.Size / scale));

                var interpolationMode = RenderOptions.GetBitmapInterpolationMode(this);
                context.Custom(new BlurImageRender(mem, destRect, sourceRect, BlurLevel, BlurLevel, null));
                // Dispatcher.UIThread.InvokeAsync(InvalidateVisual, DispatcherPriority.Background);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Renders the control.
        /// </summary>
        /// <param name="context">The drawing context.</param>
        public override void Render(DrawingContext context)
        {
            var source = Source;

            if (source != null)
            {
                Rect   viewPort   = new Rect(Bounds.Size);
                Size   sourceSize = new Size(source.PixelSize.Width, source.PixelSize.Height);
                Vector scale      = Stretch.CalculateScaling(Bounds.Size, sourceSize);
                Size   scaledSize = sourceSize * scale;
                Rect   destRect   = viewPort
                                    .CenterRect(new Rect(scaledSize))
                                    .Intersect(viewPort);
                Rect sourceRect = new Rect(sourceSize)
                                  .CenterRect(new Rect(destRect.Size / scale));

                var interpolationMode = RenderOptions.GetBitmapInterpolationMode(this);

                context.DrawImage(source, 1, sourceRect, destRect, interpolationMode);
            }
        }
Beispiel #3
0
        public override void Render(DrawingContext context)
        {
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(Data, QRCodeGenerator.ECCLevel.Q);

            QRCoder.QRCode        qrCode       = new QRCoder.QRCode(qrCodeData);
            System.Drawing.Bitmap systemBitmap = null;

            if (Icon == null)
            {
                systemBitmap = qrCode.GetGraphic(PixelsPerModule, Color.ToHex(), SpaceBrush.ToHex(), DrawQuietZones);
            }
            else
            {
                systemBitmap = qrCode.GetGraphic(PixelsPerModule, Color.FromNative(), SpaceBrush.FromNative(), Icon.FromNative(), IconScale, IconBorderWidth, DrawQuietZones);
            }

            var source = systemBitmap.ToNative();


            if (source != null && Bounds.Width > 0 && Bounds.Height > 0)
            {
                Rect viewPort   = new Rect(Bounds.Size);
                Size sourceSize = source.Size;

                Vector scale      = Stretch.Uniform.CalculateScaling(Bounds.Size, sourceSize, StretchDirection.Both);
                Size   scaledSize = sourceSize * scale;
                Rect   destRect   = viewPort
                                    .CenterRect(new Rect(scaledSize))
                                    .Intersect(viewPort);
                Rect sourceRect = new Rect(sourceSize)
                                  .CenterRect(new Rect(destRect.Size / scale));

                var interpolationMode = RenderOptions.GetBitmapInterpolationMode(this);

                context.DrawImage(source, sourceRect, destRect, interpolationMode);
            }
        }