当前位置: 首页>>代码示例>>C#>>正文


C# Canvas.UpdateLayout方法代码示例

本文整理汇总了C#中Canvas.UpdateLayout方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.UpdateLayout方法的具体用法?C# Canvas.UpdateLayout怎么用?C# Canvas.UpdateLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Canvas的用法示例。


在下文中一共展示了Canvas.UpdateLayout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Convert


//.........这里部分代码省略.........
                        _currentDC.SetStretchBltMode((StretchMode)EndianFlip(wmfReader.ReadUInt16()));

                        if (record.Size > 4)
                        {
                            wmfReader.ReadBytes(2); // Optional unused field
                        }
                        break;

                    case RecordType.META_SETTEXTALIGN:
                        _currentDC.SetTextAlign(EndianFlip(wmfReader.ReadUInt16()));

                        if (record.Size > 4)
                        {
                            wmfReader.ReadBytes(2); // Optional unused field
                        }
                        break;

                    case RecordType.META_SETTEXTCOLOR:
                        ReadSetTextColor(wmfReader);
                        break;

                    case RecordType.META_SETWINDOWEXT:
                        double extY = EndianFlip(wmfReader.ReadInt16());
                        double extX = EndianFlip(wmfReader.ReadInt16());
                        _currentDC.SetWindowExt(extX, extY);
                        break;

                    case RecordType.META_SETWINDOWORG:
                        double orgY = EndianFlip(wmfReader.ReadInt16());
                        double orgX = EndianFlip(wmfReader.ReadInt16());
                        _currentDC.SetWindowOrg(orgX, orgY);
                        break;

                    case RecordType.META_STRETCHDIB:
                        ReadStretchDib(wmfReader, record.Size);
                        break;

                    case RecordType.META_TEXTOUT:
                        ReadTextOut(wmfReader, record.Size);
                        break;

                    default:
                        // Unsupported record type
                        System.Diagnostics.Debug.WriteLine("^ UNSUPPORTED ^");

                        wmfReader.ReadBytes((int)record.Size * 2 - 6);
                        break;
                }
            }

            // Size canvas
            if (_boundingBox.Width == 0.0 | _boundingBox.Height == 0.0)
            {
                Size windowExt = _currentDC.GetWindowExt();

                if (windowExt.Width == 0.0 | windowExt.Height == 0.0)
                {
                    // TODO
                    _rootCanvas.Width = 800;
                    _rootCanvas.Height = 600;
                }
                else
                {
                    _rootCanvas.Width = windowExt.Width;
                    _rootCanvas.Height = windowExt.Height;
                }
            }
            else
            {
                if (_dpiX == 0)
                {
                    _rootCanvas.Width = _boundingBox.Width * _scale;
                    _rootCanvas.Height = _boundingBox.Height * _scale;
                }
                else
                {
                    _rootCanvas.Width = Math.Round(
                        _boundingBox.Width / 1440 * _dpiX * _scale,
                        0,
                        MidpointRounding.ToEven);
                    _rootCanvas.Height = Math.Round(
                        _boundingBox.Height / 1440 * _dpiY * _scale,
                        0,
                        MidpointRounding.ToEven);
                }
            }

            // Arrange
            var area = new Size(_rootCanvas.Width, _rootCanvas.Height);
            _rootCanvas.Measure(area);
            _rootCanvas.Arrange(new Rect
                    {
                        Height = area.Height,
                        Width = area.Width
                    }
                    );
            _rootCanvas.UpdateLayout();

            return _rootCanvas;
        }
开发者ID:bbowyersmyth,项目名称:WMF2WPF,代码行数:101,代码来源:WMF2WPF.cs

示例2: CreateImage

        /// <summary>
        /// Renders a UI control into an image.
		/// http://stackoverflow.com/questions/17355644/how-to-merge-two-images-and-show-in-an-image-control
		/// http://code.msdn.microsoft.com/merge-multiple-on-a-single-e7cdaa76
        /// </summary>
        /// <param name="control"></param>
        /// <param name="isWideTile"></param>
        /// <returns></returns>
        public static void CreateImage(UIElement control, Stream backgroundImageStream, string backgroundImage, string imagePath, SolidColorBrush backgroundColor, int maxWidth, int maxHeight)
        {
            // 1. Setup dimensions for wide tile.
            var width = maxWidth < 0 ? 480 : maxWidth;
            var height = maxHeight < 0 ? 800 : maxHeight;
            var bmp = new WriteableBitmap(width, height);

            // 2. Background image ?
            var hasBackgroundImage = !string.IsNullOrEmpty(backgroundImage);
            Image img = null;
            if (hasBackgroundImage)
            {
				img = BuildImage(backgroundImage, width, height);
            }
            
            // 2. Create canvas based on background color.
            var canvas = new Canvas();
            canvas.Width = width;
            canvas.Height = height;
            if (!hasBackgroundImage)
                canvas.Background = backgroundColor;
            canvas.Children.Add(control);
            canvas.Measure(new Size(width, height));
            canvas.Arrange(new Rect(0, 0, width, height));
            canvas.UpdateLayout();

            if(hasBackgroundImage)
                bmp.Render(img, null);

            bmp.Render(canvas, null);
            bmp.Invalidate();

            // 8. Now save the image to local folder.
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                var filename = imagePath;
                using (var st = new IsolatedStorageFileStream(filename, FileMode.Create, FileAccess.Write, store))
                {
                    bmp.SaveJpeg(st, width, height, 0, 100);
                    st.Close();
                }
            }

            try
            {
                bmp = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (Exception ex)
            {
                Slate.Core.Logging.Logger.Error("Create Image", "Warning, attempt to clear up memory for tile image failed", ex);
            }
        }
开发者ID:kishorereddy,项目名称:slate-lib,代码行数:62,代码来源:ImageHelper.cs


注:本文中的Canvas.UpdateLayout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。