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


C# Image.Measure方法代码示例

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


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

示例1: GetPage

		public override DocumentPage GetPage(int pageNumber)
		{
			var bitmap = this.exportImages[pageNumber];
			var imageSize = new Size(bitmap.Width, bitmap.Height);
			var image = new Image { Source = bitmap };
			image.Measure(imageSize);
			image.Arrange(new Rect(imageSize));
			image.UpdateLayout();
			return new DocumentPage(image);
		}
开发者ID:JoelWeber,项目名称:xaml-sdk,代码行数:10,代码来源:GanttPaginator.cs

示例2: MeasureTest_Empty

		public void MeasureTest_Empty ()
		{
			Image image = new Image ();
			
			image.Measure (new Size (50,50));

			Assert.AreEqual (new Size (0,0), image.DesiredSize);
			Assert.AreEqual (0, image.ActualWidth);
			Assert.AreEqual (0, image.ActualHeight);
		}
开发者ID:dfr0,项目名称:moon,代码行数:10,代码来源:ImageTest.cs

示例3: Measure_Should_Return_Correct_Size_For_UniformToFill_Stretch

        public void Measure_Should_Return_Correct_Size_For_UniformToFill_Stretch()
        {
            var bitmap = Mock.Of<IBitmap>(x => x.PixelWidth == 50 && x.PixelHeight == 100);
            var target = new Image();
            target.Stretch = Stretch.UniformToFill;
            target.Source = bitmap;

            target.Measure(new Size(50, 50));

            Assert.Equal(new Size(50, 50), target.DesiredSize);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:11,代码来源:ImageTests.cs

示例4: MeasureTest

		public void MeasureTest ()
		{
			Image image = new Image ();

			image.Source = new BitmapImage (new Uri ("images/mono.png", UriKind.Relative));

			image.Measure (new Size (500,500));

			Assert.AreEqual (new Size (0,0), image.DesiredSize);
			Assert.AreEqual (0, image.ActualWidth);
			Assert.AreEqual (0, image.ActualHeight);

		}
开发者ID:kangaroo,项目名称:moon,代码行数:13,代码来源:ImageTest.cs

示例5: MeasureTest2

		public void MeasureTest2 ()
		{
			Image image = new Image ();
			image.Width = 50;
			image.Height = 50;
			image.Source = new BitmapImage (new Uri ("images/mono.png", UriKind.Relative));
			image.ImageFailed += delegate { /* do nothing */ };
			
			image.Measure (new Size (500,500));

			Assert.AreEqual (new Size (0,0), image.DesiredSize);
			Assert.AreEqual (50, image.ActualWidth);
			Assert.AreEqual (50, image.ActualHeight);

		}
开发者ID:dfr0,项目名称:moon,代码行数:15,代码来源:ImageTest.cs

示例6: ParticleSystem

        public ParticleSystem(int maxCount, System.Windows.Media.Color color, Uri source)
        {
            this.maxParticleCount = maxCount;

            this.particleList = new List<Particle>();

            this.particleModel = new GeometryModel3D();
            this.particleModel.Geometry = new MeshGeometry3D();

            Image e = new Image();
            e.Source = new BitmapImage( source);

              //  Ellipse e = new Ellipse();

            e.Width = 32.0;
            e.Height = 32.0;
               // RadialGradientBrush b = new RadialGradientBrush();
               // b.GradientStops.Add(new GradientStop(System.Windows.Media.Color.FromArgb(0xFF, color.R, color.G, color.B), 0.25));
               // b.GradientStops.Add(new GradientStop(System.Windows.Media.Color.FromArgb(0x00, color.R, color.G, color.B), 1.0));

               // e.Fill = b;

            e.Measure(new System.Windows.Size(32, 32));
            e.Arrange(new Rect(0, 0, 32, 32));

            System.Windows.Media.Brush brush = null;

            #if USE_VISUALBRUSH
            brush = new VisualBrush(e);
            #else
            RenderTargetBitmap renderTarget = new RenderTargetBitmap(32, 32, 96, 96, PixelFormats.Pbgra32);
            renderTarget.Render(e);
            renderTarget.Freeze();
            brush = new ImageBrush(renderTarget);
            #endif

            DiffuseMaterial material = new DiffuseMaterial(brush);

            this.particleModel.Material = material;

            this.rand = new Random(brush.GetHashCode());
        }
开发者ID:luiseduardohdbackup,项目名称:dotnet-1,代码行数:42,代码来源:ParticleSystem.cs

示例7: AddPinTitleToDesktop

        public static void AddPinTitleToDesktop(string imageUri, string pinDestinationUri, StandardTileData newTileData)
        {
            string fileName = @"Shared\ShellContent\fbd-pintile-" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                try
                {
                    var backImage = new Image();
                    backImage.Height = backImage.Width = 173;
                    backImage.Stretch = Stretch.None;
                    backImage.Source = new BitmapImage(new Uri(imageUri, UriKind.RelativeOrAbsolute))
                        {
                            CreateOptions = BitmapCreateOptions.BackgroundCreation
                        };
                    backImage.Measure(new Size(173, 173));
                    backImage.Arrange(new Rect(0, 0, 173, 173));
                    var image = new WriteableBitmap(backImage, null);

                    string directory = Path.GetDirectoryName(fileName);
                    if (!store.DirectoryExists(directory))
                    {
                        store.CreateDirectory(directory);
                    }
                    using (var stream = store.OpenFile(fileName, FileMode.OpenOrCreate))
                    {
                        image.SaveJpeg(stream, 173, 173, 0, 100);
                    }

                    newTileData.BackgroundImage = new Uri("isostore:/" + fileName, UriKind.Absolute);

                    // Create the tile and pin it to Start. This will cause a navigation to Start and a deactivation of our application.
                    ShellTile.Create(new Uri(pinDestinationUri, UriKind.Relative), newTileData);
                }
                catch (Exception ex)
                {
                    return;
                }
            }
        }
开发者ID:NBitionDevelopment,项目名称:WindowsPhoneFeedBoard,代码行数:40,代码来源:GeneralHelper.cs

示例8: ComputeActualWidth

		public void ComputeActualWidth ()
		{
			var c = new Image ();

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual1");

			c.MaxWidth = 25;
			c.Width = 50;
			c.MinHeight = 33;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (25,33), new Size (c.ActualWidth,c.ActualHeight), "c actual1");

			c.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (25,33), new Size (c.ActualWidth,c.ActualHeight), "c actual2");
		}
开发者ID:dfr0,项目名称:moon,代码行数:19,代码来源:ImageTest.cs

示例9: LoadTestCanvas

		public void LoadTestCanvas ()
		{
			// Fails in Silverlight 3
			bool loaded = false;
			bool failed = false;
			double progress = 0.0;
			
			Image image = new Image ();
			BitmapImage bit = new BitmapImage (new Uri ("http://planet.gnome.org/heads/miguel.png"));
			bit.DownloadProgress += (sender, args) => { progress = args.Progress; };
			image.Source = bit;
			
			image.Loaded += (sender, args) => { loaded = true; };
			image.ImageFailed += (sender, args) => { failed = true; };
			
			Canvas c = new Canvas ();
			c.Children.Add (image);
			
			Enqueue (() => TestPanel.Children.Add (c));
			EnqueueConditional (() => (loaded && progress >= 100) || failed );
			Enqueue (() => {
				Assert.IsFalse (failed, "failed");
				Assert.AreEqual (100, progress, "progress");

				//				Assert.AreEqual (DependencyProperty.UnsetValue, image.ReadLocalValue (FrameworkElement.ActualWidthProperty), "local actual.width");
				//Assert.AreEqual (DependencyProperty.UnsetValue, image.ReadLocalValue (FrameworkElement.ActualHeightProperty), "local actual.height");

				Assert.AreEqual (new Size (64, 96), new Size (image.ActualWidth, image.ActualHeight), "actual");

				Assert.AreEqual (new Size (0, 0), image.DesiredSize, "desired");
				Assert.AreEqual (true, Double.IsNaN (image.Width), "specified.width");
				Assert.AreEqual (true, Double.IsNaN (image.Height), "specified.height");
				//Assert.AreEqual (new Size (Double.NaN, Double.NaN), new Size (image.Width, image.Height), "specified");
				
				image.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
				
				Assert.AreEqual (new Size (0, 0), image.DesiredSize, "desired");
				Assert.AreEqual (new Size (64, 96), new Size (image.ActualWidth, image.ActualHeight), "actual");
			});
			
			Enqueue (() => TestPanel.Children.Clear ());
			EnqueueTestComplete ();
		} 
开发者ID:dfr0,项目名称:moon,代码行数:43,代码来源:ImageTest.cs

示例10: AssertValid

    CreateLegendImages
    (
        IEnumerable<LegendControlBase> oLegendControls,
        Double dImageWidth,
        out IEnumerable<Image> oImages,
        out Double dTotalImageHeight
    )
    {
        Debug.Assert(oLegendControls != null);
        Debug.Assert(dImageWidth > 0);
        AssertValid();

        List<Image> oLegendImages = new List<Image>();
        oImages = oLegendImages;
        dTotalImageHeight = 0;

        foreach (LegendControlBase oLegendControl in oLegendControls)
        {
            if (oLegendControl.Visible && oLegendControl.Height > 0)
            {
                System.Windows.Media.Imaging.BitmapSource oBitmapSource;

                using ( System.Drawing.Bitmap oBitmap =
                    oLegendControl.DrawOnBitmap(
                        (Int32)Math.Ceiling(dImageWidth) ) )
                {
                    oBitmapSource = WpfGraphicsUtil.BitmapToBitmapSource(
                        oBitmap);
                }

                Image oLegendImage = new Image();
                oLegendImage.Source = oBitmapSource;
                oLegendImage.Width = dImageWidth;

                oLegendImage.Measure(new Size(
                    dImageWidth, Double.PositiveInfinity) );

                oLegendImages.Add(oLegendImage);
                dTotalImageHeight += oLegendImage.DesiredSize.Height;
            }
        }
    }
开发者ID:2014-sed-team3,项目名称:term-project,代码行数:42,代码来源:GraphImageCompositor.cs

示例11: Print

        /// <summary>
        /// Print this canvas.  The dialog should have already been displayed and confirmed.
        /// </summary>
        /// <param name="printDlg"></param>
        public void Print(PrintDialog printDlg)
        {
            

            System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);

            Mute = true;

            BitmapSource bs = CreateImage();

            double wid = capabilities.PageImageableArea.ExtentWidth / bs.Width;
            double hei = capabilities.PageImageableArea.ExtentHeight / bs.Height;

            Image i = new Image();
            i.Source = bs;
            i.Stretch = Stretch.Uniform;
            i.Width = capabilities.PageImageableArea.ExtentWidth;
            i.Height = capabilities.PageImageableArea.ExtentHeight;

            Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

            //update the layout of the visual to the printer page size.

            i.Measure(sz);

            i.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

            
            //now print the visual to printer to fit on the one page.

            printDlg.PrintVisual(i, "Circuit");

            Mute = false;
            UseZoomCenter = false;
            
            SizeCanvas();
        }
开发者ID:buptkang,项目名称:LogicPad,代码行数:41,代码来源:GateCanvas.xaml.cs

示例12: UpdateImagePosition

		void UpdateImagePosition(Image image) {
			double leftMargin = FilterMargin(imageSourceService.LeftMarginWidthPercent) / 100;
			double rightMargin = FilterMargin(imageSourceService.RightMarginWidthPercent) / 100;
			double topMargin = FilterMargin(imageSourceService.TopMarginHeightPercent) / 100;
			double bottomMargin = FilterMargin(imageSourceService.BottomMarginHeightPercent) / 100;
			if (double.IsNaN(leftMargin) || double.IsNaN(rightMargin) || leftMargin < 0 || rightMargin < 0 || leftMargin + rightMargin > 1) {
				leftMargin = 0;
				rightMargin = 0;
			}
			if (double.IsNaN(topMargin) || double.IsNaN(bottomMargin) || topMargin < 0 || bottomMargin < 0 || topMargin + bottomMargin > 1) {
				topMargin = 0;
				bottomMargin = 0;
			}
			double viewportWidth = (1 - leftMargin - rightMargin) * ViewportWidth;
			double viewportHeight = (1 - topMargin - bottomMargin) * ViewportHeight;
			double xOffs = leftMargin * ViewportWidth;
			double yOffs = topMargin * ViewportHeight;

			Size size;
			image.ClearValue(FrameworkElement.HeightProperty);
			image.ClearValue(FrameworkElement.WidthProperty);
			if (imageSourceService.Stretch == Stretch.None) {
				image.Stretch = Filter(imageSourceService.Stretch);
				image.StretchDirection = Filter(imageSourceService.StretchDirection);

				image.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
				size = image.DesiredSize;

				if (resizeTooBigImages && viewportWidth != 0 && viewportHeight != 0 && (size.Width > viewportWidth || size.Height > viewportHeight)) {
					image.Stretch = Stretch.Uniform;
					image.StretchDirection = StretchDirection.Both;
					image.Measure(new Size(viewportWidth, viewportHeight));
					size = image.DesiredSize;
					image.Width = size.Width;
					image.Height = size.Height;
				}
			}
			else {
				image.Measure(new Size(viewportWidth, viewportHeight));
				size = image.DesiredSize;
				image.Width = size.Width;
				image.Height = size.Height;
			}

			switch (imageSourceService.ImagePlacement) {
			case ImagePlacement.TopLeft:
				break;

			case ImagePlacement.TopRight:
				xOffs += viewportWidth - size.Width;
				break;

			case ImagePlacement.BottomLeft:
				yOffs += viewportHeight - size.Height;
				break;

			case ImagePlacement.BottomRight:
				xOffs += viewportWidth - size.Width;
				yOffs += viewportHeight - size.Height;
				break;

			case ImagePlacement.Top:
				xOffs += (viewportWidth - size.Width) / 2;
				break;

			case ImagePlacement.Left:
				yOffs += (viewportHeight - size.Height) / 2;
				break;

			case ImagePlacement.Right:
				xOffs += viewportWidth - size.Width;
				yOffs += (viewportHeight - size.Height) / 2;
				break;

			case ImagePlacement.Bottom:
				xOffs += (viewportWidth - size.Width) / 2;
				yOffs += viewportHeight - size.Height;
				break;

			case ImagePlacement.Center:
				xOffs += (viewportWidth - size.Width) / 2;
				yOffs += (viewportHeight - size.Height) / 2;
				break;

			default:
				Debug.Fail($"Unknown {nameof(ImagePlacement)} value: {imageSourceService.ImagePlacement}");
				break;
			}

			Canvas.SetLeft(image, FilterOffset(imageSourceService.HorizontalOffset) + xOffs);
			Canvas.SetTop(image, FilterOffset(imageSourceService.VerticalOffset) + yOffs);
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:92,代码来源:BackgroundImageService.cs

示例13: PrintImageLabel_MouseDown

        private async void PrintImageLabel_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                return;
            }

            PrintDialog printDialog = new PrintDialog();

            if (printDialog.ShowDialog() != true)
            {
                return;
            }

            var progressDialog = await this.ShowProgressAsync(Resource.PleaseWait, "Printing image");

            BitmapSource bitmap = ElementToBitmap(this.ViewPort);

            // Create Image element for hosting bitmap.
            Image img = new Image
            {
                Source = bitmap,
                Stretch = Stretch.None
            };

            // Get scale of the print to screen of WPF visual.
            double scale = Math.Min(
                printDialog.PrintableAreaWidth / bitmap.Width,
                printDialog.PrintableAreaHeight / bitmap.Height);

            //Transform the imgae to scale
            img.LayoutTransform = new ScaleTransform(scale, scale);

            // Get the size of the printer page.
            Size size = new Size(
                bitmap.Width * scale,
                bitmap.Height * scale);

            //update the layout of the visual to the printer page size.
            img.Measure(size);
            img.Arrange(new Rect(new Point(0, 0), size));

            // Print the Image element.
            printDialog.PrintVisual(img, Path.GetFileName(this.filePath));

            await progressDialog.CloseAsync();
        }
开发者ID:oleksadobrianskyy,项目名称:ModelViewer3D,代码行数:47,代码来源:MainWindow.xaml.cs

示例14: ThreadFunc

		private static void ThreadFunc(object state)
		{
			while (true)
			{
				var request = imageQueue.Take();

				int width = request.Width;
				int height = request.Heigth;
				Image image = new Image { Width = width, Height = height, Source = request.DrawingImage, Stretch = Stretch.Fill };
				image.Measure(new Size(width, height));
				image.Arrange(new Rect(0, 0, width, height));
				image.Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.Background);

#if false
				Window window = new Window();
				window.Content = image;
				window.Show();
#endif

				RenderTargetBitmap renderBitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
				renderBitmap.Render(image);
				image.Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.Background);

				int[] pixels = new int[width * height];
				renderBitmap.CopyPixels(pixels, (width * PixelFormats.Pbgra32.BitsPerPixel + 7) / 8, 0);

				resultQueue.Add(pixels);
			}
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:29,代码来源:ImageHelper.cs

示例15: RenderCurve

        private void RenderCurve(
			int width,
			IEnumerable<IList<Point>> collection,
			double thickness,
			int miterLimit,
			int height,
			int stride,
			out byte[] bitmap,
			out byte[] selection)
        {
            if (_renderTargetBitmap == null
                || _renderTargetBitmap.PixelWidth != width
                || _renderTargetBitmap.PixelHeight != height)
            {
                _renderTargetBitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
                _formatConvertedBitmap = new FormatConvertedBitmap(_renderTargetBitmap, DrawingParameter.TargetPixelFormat, DrawingParameter.TargetBitmapPalette, 1);

                _blurImage = new Image
                    {
                        Effect = new BlurEffect
                            {
                                Radius = 15,
                                KernelType = KernelType.Gaussian
                            },
                        Source = _renderTargetBitmap
                    };
                _blurImage.Measure(new Size(width, height));
                _blurImage.Arrange(new Rect(0, 0, width, height));
                _blurImage.InvalidateVisual();
                _selectionRtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
                _selectionFcb = new FormatConvertedBitmap(_selectionRtb, DrawingParameter.TargetPixelFormat, DrawingParameter.TargetBitmapPalette, 1);
            }
            else
            {
                _renderTargetBitmap.Clear();
                _selectionRtb.Clear();
            }

            collection
                .Select(it =>
                    {
                        try
                        {
                            var visual = _drawingVisualFactory();
                            visual.Draw(it, thickness, miterLimit, _logicalToScreenMapperFactory());
                            return visual;
                        }
                        // Kann vorkommen, wenn der Container schon disposed ist, aber noch gezeichnet werden soll
                        catch (ObjectDisposedException)
                        {
                            return new DrawingVisual();
                        }
                    })
                .ForEachElement(_renderTargetBitmap.Render);

            bitmap = new byte[stride * height];
            _formatConvertedBitmap.CopyPixels(bitmap, stride, 0);

            //selection = bitmap;
            //return;

            //var writeableBitmap = new WriteableBitmap(width, height, 96, 96, DrawingParameter.TargetPixelFormat, DrawingParameter.TargetBitmapPalette);
            //writeableBitmap.Lock();
            //var rect = new Int32Rect(0, 0, width, height);
            //writeableBitmap.WritePixels(rect, bitmap, stride, 0);
            //writeableBitmap.AddDirtyRect(rect);
            //writeableBitmap.Unlock();
            // set the image to the original

            _selectionRtb.Render(_blurImage);
            selection = new byte[stride * height];
            _selectionFcb.CopyPixels(selection, stride, 0);

            // ABSOLUT notwendig, da es ansonsten MemoryLeaks gibt
            // siehe hier: http://stackoverflow.com/questions/192329/simple-wpf-sample-causes-uncontrolled-memory-growth
            _blurImage.UpdateLayout();

            //var png = new PngBitmapEncoder();
            //png.Frames.Add(BitmapFrame.Create(imageRtb));
            //using (var fs = new FileStream("c:\\temp\\test6.png", FileMode.Create))
            //    png.Save(fs);
        }
开发者ID:Bruhankovi4,项目名称:Emotyper,代码行数:82,代码来源:WpfBlurSelectionDrawer.cs


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