Question

I have a texture image as .jpg and I want to use this image as Windows.Media.pen

I use Windows.Media.pen for drawing skeleton data in DrawingContext which I got it from microsoft kinect.

How can I use texture image .jpg as Windows.Media.pen?


solved the problem.

ImageSource image = new BitmapImage(new Uri(@"...\texture.jpg", UriKind.Relative));
var brush = new ImageBrush(image);
var pen = new Pen(brush, 10);
drawingContext.DrawLine(pen, XPos, YPos);
Was it helpful?

Solution

Welcome to StackOverflow :D

Not sure if you'd get what you've been expecting as you can see below but here's how to do it :

You need to use ImageBrush to be able to assign an image to a Pen.

Original image :

enter image description here

Result :

enter image description here

Code :

ImageSource image = new BitmapImage(new Uri(@"..\..\5c5f910416e2b92bb73fa59c56fe695d.png", UriKind.Relative));
var brush = new ImageBrush(image);
var pen = new Pen(brush, 50);
var drawingVisual = new DrawingVisual();
using (DrawingContext drawingContext = drawingVisual.RenderOpen())
{
    drawingContext.DrawRectangle(null, pen, new Rect(new Size(200, 200)));
}

var renderTargetBitmap = new RenderTargetBitmap(200, 200, 96, 96, PixelFormats.Pbgra32);
renderTargetBitmap.Render(drawingVisual);
Content = new Image {Source = renderTargetBitmap, Stretch = Stretch.None};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top