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


C# Imaging.RenderTargetBitmap类代码示例

本文整理汇总了C#中System.Windows.Media.Imaging.RenderTargetBitmap的典型用法代码示例。如果您正苦于以下问题:C# RenderTargetBitmap类的具体用法?C# RenderTargetBitmap怎么用?C# RenderTargetBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RenderTargetBitmap类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了RenderTargetBitmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateBitmap

        public void CreateBitmap()
        {
            int width = 100;
            int height = 100;
            int dpi = 96;

            Tracing.Log(">> CreateBitmap");
            var thread = new Thread(new ThreadStart(() => 
            {
                Tracing.Log(">> CreateBitmap - Thread start; creating drawing visual");
                //Dispatcher.Invoke(new Action(() => {
                _drawingVisual = new DrawingVisual();
                _drawingContext = _drawingVisual.RenderOpen();
                //}));

                Tracing.Log(">> CreateBitmap - Drawing to context");
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.HotPink), new Pen(), new Rect(0, 0, 50, 50));
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.Blue), new Pen(), new Rect(50, 0, 50, 50));
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.Orange), new Pen(), new Rect(0, 50, 50, 50));
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.DarkRed), new Pen(), new Rect(50, 50, 50, 50));
                _drawingContext.Close();

                Tracing.Log(">> CreateBitmap - Finished drawing; creating render target bitmap");
                _bitmap = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Default);
                _bitmap.Render(_drawingVisual);
                Tracing.Log(">> CreateBitmap - Finished work");
                _bitmap.Freeze();
            }));
            //thread.IsBackground = true;
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
开发者ID:pascalfr,项目名称:MPfm,代码行数:32,代码来源:TestControl.cs

示例2: Create3DViewPort

        private void Create3DViewPort()
        {
            var hvp3d = new HelixViewport3D();
            Viewport3D vp3d = new Viewport3D();
            var lights = new DefaultLights();
            var tp = new Teapot();

            hvp3d.Children.Add(lights);
            hvp3d.Children.Add(tp);

            vp3d = hvp3d.Viewport;
            tata.Children.Add(vp3d); // comenter ca pour test

            /* MEGA TEST DE L'ESPACE SUBSAHARIEN */

            RenderTargetBitmap bmp = new RenderTargetBitmap(800, 800, 96, 96, PixelFormats.Pbgra32);
            var rect = new Rect(0, 0, 800, 800);
            vp3d.Measure(new Size(800, 800));
            vp3d.Arrange(rect);
            vp3d.InvalidateVisual();
            
            bmp.Render(vp3d);

            PngBitmapEncoder png = new PngBitmapEncoder();
            png.Frames.Add(BitmapFrame.Create(bmp));

            String filepath = "C:\\Users\\Remi\\Desktop\\canardmasque.png";
            using (Stream stm = File.Create(filepath))
            {
                png.Save(stm);
            }
        }
开发者ID:remi-hernandez,项目名称:renderHelixViewPort3d,代码行数:32,代码来源:MainWindow.xaml.cs

示例3: ButtonSave_Click

        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            var rect = new Rect { Width = 512, Height = 384 };
            var dv = new DrawingVisual();

            var dc = dv.RenderOpen();
            dc.PushTransform(new TranslateTransform(-rect.X, -rect.Y));
            dc.DrawRectangle(InkCanvasMain.Background, null, rect);
            InkCanvasMain.Strokes.Draw(dc);
            dc.Close();

            var rtb = new RenderTargetBitmap((int)rect.Width, (int)rect.Height, 96, 96, PixelFormats.Default);
            rtb.Render(dv);
            var enc = new PngBitmapEncoder();
            enc.Frames.Add(BitmapFrame.Create(rtb));

            var fn = TextBoxFileName.Text;
            if (!fn.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) fn += ".png";
            using (Stream s = File.Create(TegakiImageFolder + "/" + fn))
            {
                enc.Save(s);
            }
            ((TegakiWindowViewModel)DataContext).AddToMediaList(System.IO.Path.GetFullPath(TegakiImageFolder + "/" + fn));
            Close();
        }
开发者ID:kb10uy,项目名称:Kbtter4,代码行数:25,代码来源:TegakiWindow.xaml.cs

示例4: getFeatures

        private double[] getFeatures()
        {
            rtb = new RenderTargetBitmap((int)InkCanvas1.ActualWidth, (int)InkCanvas1.ActualHeight,
                96d, 96d, PixelFormats.Default);

            rtb.Render(InkCanvas1);

            //save the ink to a memory stream
            BmpBitmapEncoder encoder = new BmpBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(rtb));

            byte[] bitmapBytes;
            Bitmap bmp;
            using (MemoryStream ms = new MemoryStream())
            {
                encoder.Save(ms);
                ms.Position = 0;
                bitmapBytes = ms.ToArray();

                ms.Seek(0, SeekOrigin.Begin);
                bmp = new Bitmap(ms);
            }

            bmp = resize.Apply(bmp);

            double[] features = ToFeatures(bmp);

            return features;
        }
开发者ID:CanerPatir,项目名称:framework,代码行数:29,代码来源:DrawingCanvas.xaml.cs

示例5: CreateCursor

    public static Cursor CreateCursor(UIElement element, int xHotSpot, 
        int yHotSpot)
    {
      element.Measure(new Size(double.PositiveInfinity, 
        double.PositiveInfinity));
      element.Arrange(new Rect(0, 0, element.DesiredSize.Width, 
        element.DesiredSize.Height));

      RenderTargetBitmap rtb = 
        new RenderTargetBitmap((int)element.DesiredSize.Width, 
          (int)element.DesiredSize.Height, 96, 96, PixelFormats.Pbgra32);
      rtb.Render(element);

      PngBitmapEncoder encoder = new PngBitmapEncoder();
      encoder.Frames.Add(BitmapFrame.Create(rtb));

      MemoryStream ms = new MemoryStream();
      encoder.Save(ms);

      System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);

      ms.Close();
      ms.Dispose();     

      Cursor cur = InternalCreateCursor(bmp, xHotSpot, yHotSpot);

      bmp.Dispose();

      return cur;
    }
开发者ID:heinzsack,项目名称:DEV,代码行数:30,代码来源:CursorHelper.cs

示例6: Convert

        public void Convert(IEnumerable<IAssetImageSource> sources, string target, VisualAssetInfo visualAsset)
        {
            if (sources == null)
            {
                throw new ArgumentNullException("sources");
            }
            if (string.IsNullOrEmpty(target))
            {
                throw new ArgumentNullException("target");
            }
            if (visualAsset == null)
            {
                throw new ArgumentNullException("visualAsset");
            }

            var rectangle = this.GetRectangleBounds(visualAsset.Width, visualAsset.Height, visualAsset.Margin);
            var drawingVisual = this.CreateDrawingVisual(sources, rectangle);

            var targetBitmap = new RenderTargetBitmap(visualAsset.Width, visualAsset.Height, 96, 96, PixelFormats.Pbgra32);
            targetBitmap.Render(drawingVisual);

            var png = new PngBitmapEncoder();
            png.Frames.Add(BitmapFrame.Create(targetBitmap));

            using (var stream = new FileStream(target, FileMode.Create, FileAccess.Write))
            {
                png.Save(stream);
            }
        }
开发者ID:duracellko,项目名称:WindowsApp-VisualAssets,代码行数:29,代码来源:ImageAssetConverter.cs

示例7: Convert

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Converts a Canvas to an image source
            var canvas = value as Canvas;
            if (canvas == null)
            {
                return null;
            }
            var param = parameter as CanvasToImageSourceParameters;
            double width = canvas.Width;
            double height = canvas.Height;
            if (param != null)
            {
                width = param.Width;
                height = param.Height;
            }

            if (!canvas.IsMeasureValid)
            {
                canvas.Measure(new Size(width, height));
                canvas.Arrange(new Rect(0, 0, width, height));
                canvas.UpdateLayout();                
            }

            var rtb = new RenderTargetBitmap((int)width, (int)height, 96d, 96d, PixelFormats.Pbgra32);
            rtb.Render(canvas);
            var bmp = GetBitmap(rtb);
            return rtb;
        }
开发者ID:dEMonaRE,项目名称:HearthstoneTracker,代码行数:29,代码来源:CanvasToImageSourceConverter.cs

示例8: DrawGraphicsOnBitmap

        public DrawGraphicsOnBitmap()
        {
            Title = "Draw Graphics on Bitmap";

            // ��Ʈ���� ������� �����ϱ� ���� ����� ������.
            Background = Brushes.Khaki;

            // RenderTargetBitmap ������.
            RenderTargetBitmap renderbitmap = new RenderTargetBitmap(100, 100, 96, 96, PixelFormats.Default);

            // DrawingVisual ��ü�� ������.
            DrawingVisual drawvis = new DrawingVisual();
            DrawingContext dc = drawvis.RenderOpen();      // Render �޼ҵ� ȣ��
            dc.DrawRoundedRectangle(Brushes.Blue, new Pen(Brushes.Red, 10),
                                    new Rect(25, 25, 50, 50), 10, 10);
            dc.Close();

            // RenderTargetBitmap ���� DrawingVisual ��ü�� �׸�.
            renderbitmap.Render(drawvis);

            // �̹��� ��ä ���� -> ������Ƽ ����
            Image img = new Image();
            img.Source = renderbitmap;

            // ���
            Content = img;
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:27,代码来源:DrawGraphicsOnBitmap.cs

示例9: XamlDrawingToPngBase64String

		/// <summary>
		///     Преобразует XAML Drawing/DrawingGroup в png base64 string
		/// </summary>
		/// <param name="width"></param>
		/// <param name="height"></param>
		/// <param name="drawing"></param>
		/// <returns>Base64 string containing png bitmap</returns>
		public static string XamlDrawingToPngBase64String(int width, int height, Drawing drawing) {
			var bitmapEncoder = new PngBitmapEncoder();
			// The image parameters...
			double dpiX = 96;
			double dpiY = 96;

			// The Visual to use as the source of the RenderTargetBitmap.
			var drawingVisual = new DrawingVisual();
			using (var drawingContext = drawingVisual.RenderOpen()) {
				drawingContext.DrawDrawing(drawing);
			}

			var bounds = drawingVisual.ContentBounds;

			var targetBitmap = new RenderTargetBitmap(
				width * 10, height * 10, dpiX, dpiY,
				PixelFormats.Pbgra32);
			drawingVisual.Transform = new ScaleTransform(width * 10 / bounds.Width, height * 10 / bounds.Height);

			targetBitmap.Render(drawingVisual);

			// Encoding the RenderBitmapTarget as an image.
			bitmapEncoder.Frames.Add(BitmapFrame.Create(targetBitmap));

			byte[] values;
			using (var str = new MemoryStream()) {
				bitmapEncoder.Save(str);
				values = str.ToArray();
			}
			return Convert.ToBase64String(values);
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:38,代码来源:InternalConverter.cs

示例10: CreatePdfDocument

        public Document CreatePdfDocument(Chart chart, string path)
        {
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
                (int) chart.ActualWidth,
                (int) chart.ActualHeight,
                96d,
                96d,
                PixelFormats.Pbgra32);

            renderBitmap.Render(chart);

            MemoryStream stream = new MemoryStream();
            BitmapEncoder encoder = new BmpBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
            encoder.Save(stream);

            Bitmap bitmap = new Bitmap(stream);
            System.Drawing.Image image = bitmap;

            System.Drawing.Image resizedImage = ResizeImage(image, image.Width*2, image.Height);

            Document doc = new Document(PageSize.A4);
            PdfWriter.GetInstance(doc, new FileStream(path, FileMode.OpenOrCreate));
            doc.Open();
            Image pdfImage = Image.GetInstance(resizedImage, ImageFormat.Jpeg);
            doc.Add(pdfImage);
            doc.Close();
            
            return doc;
        }
开发者ID:LexaGal,项目名称:Plants,代码行数:30,代码来源:PdfDocumentCreator.cs

示例11: OnUpdate

        protected override void OnUpdate(double[] values)
        {
            const double space = 3;
            const double barwidth = 8;

            int pts = values.Length / 2;

            int width = 1000;//pts * (space + barwidth) - space;
            int height = width / 4;
            if (_bmp == null || width != _bmp.PixelWidth)
            {
                _bmp = new RenderTargetBitmap(width, height, 120, 96, PixelFormats.Pbgra32);
            }
            DrawingVisual drawingVisual = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();
            Brush brush = DrawingBrush.Clone();
            brush.Freeze();

            double totalWidth = width / pts;
            double totalBarWidth = totalWidth * ((barwidth) / (barwidth + space));
            double totalSpace = totalWidth * ((space) / (barwidth + space));
            for (int i = 0; i < pts; i++)
            {
                double x = i * totalWidth;
                double y1 = height;
                double y2 = y1 - values[i] * height;
                drawingContext.DrawRectangle(brush, null, new Rect(x, y2, totalBarWidth, y1));
            }

            drawingContext.Close();
            _bmp.Clear();
            _bmp.Render(drawingVisual);
            PART_visualationDisplay.Source = _bmp;
        }
开发者ID:CheViana,项目名称:AudioLab,代码行数:34,代码来源:PeakSpectrum.cs

示例12: GetNewMessagesNotificationOverlay

		public static ImageSource GetNewMessagesNotificationOverlay(Window window, DataTemplate template, int count = 0)
		{
			if (window == null)
				return null;

			var presentation = PresentationSource.FromVisual(window);
			if (presentation == null)
				return null;
			Matrix m = presentation.CompositionTarget.TransformToDevice;
			double dx = m.M11;
			double dy = m.M22;

			double iconWidth = 16.0 * dx;
			double iconHeight = 16.0 * dy;

			string countText = count.ToString();

			RenderTargetBitmap bmp = new RenderTargetBitmap((int) iconWidth, (int) iconHeight, 96, 96, PixelFormats.Default);

			ContentControl root = new ContentControl
			{
				ContentTemplate = template,
				Content = count > 99 ? "…" : countText
			};

			root.Arrange(new Rect(0, 0, iconWidth, iconHeight));

			bmp.Render(root);

			return bmp;
		}
开发者ID:kveretennicov,项目名称:kato,代码行数:31,代码来源:Taskbarhelper.cs

示例13: ButtonBase_OnClick

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var bitmap = new RenderTargetBitmap((int)Math.Ceiling(Grid.RenderSize.Width), (int)Math.Ceiling(Grid.RenderSize.Height), 96, 96, PixelFormats.Default);
            bitmap.Render(Grid);

            Grid.Effect = new CircleRevealTransitionEffect
            {
                OldImage = new ImageBrush(bitmap),
                Reverse = !ToggleButton.IsChecked.Value
            };

            TaskbarItemInfo = ToggleButton.IsChecked == true
                ? new TaskbarItemInfo {ProgressState = TaskbarItemProgressState.Indeterminate}
                : new TaskbarItemInfo {ProgressState = TaskbarItemProgressState.None};

            Application.Current.Resources["Dunno"] = ToggleButton.IsChecked == true ? Application.Current.Resources["Dunno2"] : Application.Current.Resources["Dunno1"];

            Grid.Background = ToggleButton.IsChecked == true ? Brushes.Transparent : _background;
            OnAirImage.Visibility = ToggleButton.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;

            _compositeNodeViewModel.ResetNodes();

            _sw = Stopwatch.StartNew();
            _timer?.Stop();
            _timer = new DispatcherTimer(TimeSpan.FromMilliseconds(10), DispatcherPriority.Normal, Callback, Dispatcher);
        }
开发者ID:misupov,项目名称:Turbina,代码行数:26,代码来源:MainWindow.xaml.cs

示例14: ExportToPng

        public static byte[] ExportToPng(this FrameworkElement surface)
        {
            var transform = surface.LayoutTransform;
            surface.LayoutTransform = null;

            var size = new Size(surface.ActualWidth, surface.ActualHeight);
            surface.Measure(size);
            surface.Arrange(new Rect(size));

            var renderBitmap = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Pbgra32);
            renderBitmap.Render(surface);

            try
            {
                using (var outStream = new MemoryStream())
                {
                    var encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
                    encoder.Save(outStream);
                    return outStream.ToArray();
                }
            }
            finally 
            {
                surface.LayoutTransform = transform;
            }
        }
开发者ID:PeletonSoft,项目名称:Sketch,代码行数:27,代码来源:ImageCaptureHelper.cs

示例15: GetJpgImage

        /// 
        /// Gets a JPG "screenshot" of the current UIElement 
        /// 
        /// UIElement to screenshot 
        /// Scale to render the screenshot 
        /// JPG Quality 
        /// Byte array of JPG data 
        public byte[] GetJpgImage(double scale, int quality, int dpi)
        {
            double actualHeight = this.RootVisual.RenderSize.Height;
            double actualWidth = this.RootVisual.RenderSize.Width;

            double renderHeight = actualHeight * scale;
            double renderWidth = actualWidth * scale;

            RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)renderWidth, (int)renderHeight, dpi, dpi, PixelFormats.Pbgra32);
            VisualBrush sourceBrush = new VisualBrush(this.RootVisual);

            DrawingVisual drawingVisual = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            using (drawingContext)
            {
                drawingContext.PushTransform(new ScaleTransform(scale, scale));
                drawingContext.DrawRectangle(sourceBrush, null, new Rect(new Point(0, 0), new Point(actualWidth, actualHeight)));
            }

            renderTarget.Render(drawingVisual);
            JpegBitmapEncoder jpgEncoder = new JpegBitmapEncoder();
            jpgEncoder.QualityLevel = quality;
            jpgEncoder.Frames.Add(BitmapFrame.Create(renderTarget));

            Byte[] _imageArray;
            using (MemoryStream outputStream = new MemoryStream())
            {
                jpgEncoder.Save(outputStream);
                _imageArray = outputStream.ToArray();
            }

            return _imageArray;
        }
开发者ID:CadeLaRen,项目名称:digiCamControl,代码行数:41,代码来源:PhotoCard.cs


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