user3281625
user3281625

Reputation: 21

Convert DrawingImage into Geometry

I have several DrawingImages that were created in a ResourceDictionary (in a .xaml file).
I also have a 'Path', that I want to set its 'Data' property. So, I want to 1) Get access to a Resource 2) Cast it to DrawingImage 3) Manipulate it to the point where I can get access to the Geometry that draws it. 4) Store that Geometry in Path.Data

Upvotes: 0

Views: 1185

Answers (2)

Jesse Chisholm
Jesse Chisholm

Reputation: 4025

You can load your DrawingImage from the resource pretty easily:

(1) and (2) in your post:

var dImage = Application.Current.Resources["someImage"] as DrawimgImage;
var dBrush = Application.Current.Resources["someBrush"] as DrawimgBrush;

I listed both DrawingImage and DrawingBrush because some tools save it one way and some the other, but the inner Drawing is identical for the sake of this conversation.

You start your access descent with dImage.Drawing but where you dig from there and what you change is up to you. You may find it easier to create a new GeometryDrawing and set your path data into it, then replace the contents of the Drawing with this new GeometryDrawing.

Upvotes: 0

Glen Thomas
Glen Thomas

Reputation: 10744

IF the DrawingImage.Drawing is of type GeometryDrawing then you could try getting the GeometryDrawing.Geometry and getting the data from that.

IF the Geometry is of type PathGeometry you could get the Figures property and try work with that. PathGeometry.Figures and Path.Data are just about the same thing.

The question you have asked is huge. There are many different possibilities and a great deal of code would need to be written to tackle the problem.

Upvotes: 2

Related Questions