Example #1
0
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);
            this._blackBrush       = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1));
            this._yellowGreenBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(0x9ACD32, 1));

            GradientStop[] stops = new GradientStop[] {
                new GradientStop(0, Color.FromKnown(Colors.Yellow, 1)),
                new GradientStop(1, Color.FromKnown(Colors.ForestGreen, 1))
            };

            using (GradientStopCollection collection = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp))
            {
                this._linearGradientBrush = renderTarget.CreateLinearGradientBrush(
                    new LinearGradientBrushProperties(new PointF(0, 0), new PointF(150, 150)),
                    BrushProperties.Default,
                    collection);
                this._radialGradientBrush = renderTarget.CreateRadialGradientBrush(
                    new RadialGradientBrushProperties(new PointF(75, 75), new PointF(0, 0), 75, 75),
                    BrushProperties.Default,
                    collection);
            }

            using (Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "fern.jpg"))
            {
                this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap,
                                                                   new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.Linear),
                                                                   BrushProperties.Default);
            }

            this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromRGB(0.93f, 0.94f, 0.96f));
        }
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);

            float width  = ClientSize.Width / _dpiScaleX;
            float height = ClientSize.Height / _dpiScaleY;

            this._textLayout = DirectWriteFactory.CreateTextLayout(
                _text,
                this._textFormat,
                width,
                height);

            using (Typography typography = DirectWriteFactory.CreateTypography())
            {
                typography.AddFontFeature(FontFeatureTag.StylisticSet7, 1);
                this._textLayout.SetTypography(typography, new TextRange(0, _text.Length));
            }

            Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "heart.png");

            this._bitmapInlineObject = new BitmapInlineObject(RenderTarget, bitmap);

            this._textLayout.SetInlineObject(this._bitmapInlineObject, new TextRange(2, 1));

            this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1));
        }
        protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory)
        {
            base.OnCreateDeviceIndependentResources(factory);

            this._textFormat = DirectWriteFactory.CreateTextFormat("Gabriola",
                                                                   FontWeight.Normal,
                                                                   FontStyle.Normal,
                                                                   FontStretch.Normal,
                                                                   72);

            this._textFormat.TextAlignment      = TextAlignment.Center;
            this._textFormat.ParagraphAlignment = ParagraphAlignment.Center;

            float width  = ClientSize.Width / _dpiScaleX;
            float height = ClientSize.Height / _dpiScaleY;

            this._textLayout = DirectWriteFactory.CreateTextLayout(
                _text,
                this._textFormat,
                width,
                height);

            using (Typography typography = DirectWriteFactory.CreateTypography())
            {
                typography.AddFontFeature(FontFeatureTag.StylisticSet7, 1);
                this._textLayout.SetTypography(typography, new TextRange(0, _text.Length));
            }

            Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "heart.png");

            this._bitmapInlineObject = new BitmapInlineObject(RenderTarget, bitmap);

            this._textLayout.SetInlineObject(this._bitmapInlineObject, new TextRange(2, 1));
        }
Example #4
0
 private Bitmap LoadBitmap(string path)
 {
     using (WicBitmapDecoder decoder = ImagingFactory.CreateDecoder(ImagePath, Guid.Empty, DesiredAccess.Read, DecodeOptions.MetadataCacheOnDemand))
     {
         using (WicBitmapFrameDecode frame = decoder.GetFrame(0))
         {
             using (WicFormatConverter converter = ImagingFactory.CreateFormatConverter())
             {
                 converter.Convert(frame, WicPixelFormats.PixelFormat32bppPBGRA, BitmapDitherType.None, null, 0, BitmapPaletteType.Custom);
                 return(RenderTarget.CreateBitmap(converter, new BitmapProperties()));
             }
         }
     }
 }
Example #5
0
        protected override void OnCreateResources(RenderTarget target)
        {
            // We don't need to free any resources because the base class will
            // call OnFreeResources if necessary before calling this method.

            RedBrush = target.CreateSolidColorBrush(new ColorF(1, 0, 0));

            //whiteBrush = RenderTarget.CreateSolidColorBrush(new ColorF(1, 1, 1));
            _d2DBitmap = target.CreateBitmap(target.PixelSize,
                                             new BitmapProperties(new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.PixelFormat(Format.B8G8R8A8UNorm, AlphaMode.Premultiplied), 96, 96));

            textFormat = writeFactory.CreateTextFormat("Arial", 12);

            base.OnCreateResources(target);             // Call this last to start the animation
        }
 public unsafe static void OverlayToTarget(RenderTarget target, ImageAdapter image)
  {
      SizeU size = new SizeU((uint)image.Width, (uint)image.Height);
      D2DBitmap d2dImage = target.CreateBitmap(size, new BitmapProperties(new PixelFormat(Microsoft.WindowsAPICodePack.DirectX.Graphics.Format.B8G8R8A8UNorm, AlphaMode.Premultiplied), target.Dpi.X, target.Dpi.Y));
           
            
      uint left = 0;
      uint top = 0;
      RectU rect = new RectU(left, top, left + (uint)image.Width, top + (uint)image.Height);
      //System.Drawing.Imaging.BitmapData bmData = value.LockBits(new Rectangle(0, 0, value.Width, value.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, value.PixelFormat);
      d2dImage.CopyFromMemory(rect, (IntPtr)image.ImageBuffer, (uint)image.Width * 4);
      RectF rf = new RectF(0, 0, image.Width, image.Height);
      target.DrawBitmap(d2dImage, 1, BitmapInterpolationMode.Linear,rf );
      d2dImage.Dispose();
  }