Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            _render = new PlatformRenderInterface();
            PerspexLocator.CurrentMutable.Bind<IPlatformRenderInterface>().ToConstant(_render);
            _geometry =  new StreamGeometry();
            _rbitmap = new RenderTargetBitmap(50, 50);
            _renderTarget = _render.CreateRenderer(new PlatformHandle(Handle, "HWND"), ClientSize.Width,
                ClientSize.Height);
            var timer = new Timer() {Interval = 20};
            timer.Tick += delegate { Invalidate(); };
            timer.Start();
            components.Add(timer);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            using (var ctx = _geometry.Open())
            {
                ctx.BeginFigure(new Point(10,10), true);
                ctx.LineTo(new Point(40,25));
                ctx.BezierTo(new Point(50, 45), new Point(43, 48), new Point(20, 90));
                ctx.LineTo(new Point(10, 60));
                ctx.EndFigure(true);
            }

            _text =
                new FormattedText(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
                    "Arial", 25, FontStyle.Normal, TextAlignment.Left, FontWeight.Normal);

            _text.Constraint = new Size(400, double.PositiveInfinity);

            using (var ctx = _rbitmap.CreateDrawingContext())
                ctx.DrawRectangle(new Pen(new SolidColorBrush(Colors.Aqua)), new Rect(10, 10, 30, 30), 5);

            _bitmap = new Bitmap(@"C:\Users\keks\Desktop\phoenix.png");
        }
Exemplo n.º 2
0
 /// <summary>
 /// Init.
 /// </summary>
 public ImageAdapter(Bitmap image)
 {
     _image = image;
 }
Exemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="image"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XImage image, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            var _dc = dc as IDrawingContext;

            var rect = CreateRect(
                image.TopLeft,
                image.BottomRight,
                dx, dy);

            if (image.IsStroked || image.IsFilled)
            {
                Brush brush = ToSolidBrush(image.Style.Fill);
                Pen pen = ToPen(image.Style, _scaleToPage);

                DrawRectangleInternal(
                    _dc,
                    brush,
                    pen,
                    image.IsStroked,
                    image.IsFilled,
                    ref rect);

                // TODO: brush.Dispose();
                // TODO: pen.Dispose();
            }

            if (_enableImageCache
                && _biCache.ContainsKey(image.Path))
            {
                var bi = _biCache[image.Path];
                _dc.DrawImage(
                    bi,
                    1.0,
                    new Rect(0, 0, bi.PixelWidth, bi.PixelHeight),
                    new Rect(rect.X, rect.Y, rect.Width, rect.Height));
            }
            else
            {
                if (_state.ImageCache == null || string.IsNullOrEmpty(image.Path))
                    return;

                var bytes = _state.ImageCache.GetImage(image.Path);
                if (bytes != null)
                {
                    using (var ms = new System.IO.MemoryStream(bytes))
                    {
                        var bi = new Bitmap(ms);

                        if (_enableImageCache)
                            _biCache[image.Path] = bi;

                        _dc.DrawImage(
                            bi,
                            1.0,
                            new Rect(0, 0, bi.PixelWidth, bi.PixelHeight),
                            new Rect(rect.X, rect.Y, rect.Width, rect.Height));

                        // TODO:
                        //if (!_enableImageCache)
                        //    bi.Dispose();
                    }
                }
            }
        }
Exemplo n.º 4
0
 public ImageTests()
     : base(@"Controls\Image")
 {
     this.bitmap = new Bitmap(Path.Combine(this.OutputPath, "test.png"));
 }