Spen D
Spen D

Reputation: 4345

WPF Polygon to bitmap

How can I convert the wpf polygon shape as a bitmap image? I am trying to send as Visual parameter to change as bitmap, but it doesn't seem to be working. Is there any other way to convert the WPF polygon to bitmap?

am using like below

RenderTargetBitmap RTbmap = new RenderTargetBitmap((int)yellowPolygon.Width, (int)yellowPolygon.Height, 96, 96, PixelFormats.Default);
RTbmap.Render(yellowPolygon); 
image1.Source = RTbmap;

Upvotes: 1

Views: 2105

Answers (2)

Kūrosh
Kūrosh

Reputation: 452

use

(int)image1.ActualWidth 

and

(int)image1.ActualHeight

Upvotes: 0

NVM
NVM

Reputation: 5552

Change Width and Height to ActualWidth and ActualHeight.

Line, polygon etc which are defined via points have undefined width and height. When rendering to a bitmap you should use ActualWidth and ActualHeight.

I just tried this in a sample project and it works just fine.

Upvotes: 1

Related Questions