je le code suivant:RenderTargetBitmap ne semble pas rendre mon rectangle
LinearGradientBrush linGrBrush = new LinearGradientBrush();
linGrBrush.StartPoint = new Point(0,0);
linGrBrush.EndPoint = new Point(1, 0);
linGrBrush.GradientStops.Add(new GradientStop(Colors.Red, 0.0));
linGrBrush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.5));
linGrBrush.GradientStops.Add(new GradientStop(Colors.White, 1.0));
Rectangle rect = new Rectangle();
rect.Width = 1000;
rect.Height = 1;
rect.Fill = linGrBrush;
rect.Arrange(new Rect(0, 0, 1, 1000));
rect.Measure(new Size(1000, 1));
Si je
myGrid.Children.Add(rect);
Ensuite, le gradient est tiré bien sur la fenêtre. Je veux utiliser ce dégradé pour une carte d'intensité ailleurs, donc j'ai besoin d'en extraire les pixels. Pour ce faire, je comprends que je peux le convertir en bitmap, en utilisant RenderTargetBitmap
. Voici la partie suivante du code:
RenderTargetBitmap bmp = new RenderTargetBitmap(
1000,1,72,72,
PixelFormats.Pbgra32);
bmp.Render(rect);
Image myImage = new Image();
myImage.Source = bmp;
Pour tester cela, je fais:
myGrid.Children.Add(myImage);
Mais rien n'apparaît à la fenêtre. Qu'est-ce que je fais mal?
que [ce] (http://stackoverflow.com/questions/11237524/is-it-possible-to-brush-a -drawingvisual) et [msdn] (https://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap (v = vs.110) .aspx) alors aidez –