Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Graphics Transformation Problem
Message
From
06/04/2009 14:51:30
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01392928
Message ID:
01393520
Views:
30
>>Hi,
>>
>>Don't know if I can describe this well enough but:
>>
>>I have a Geometry which defines a shape (in the non-WPF meaning of the word). As an example assume it looks like a + sign.
>>I use this as the Data property for a Path control.
>>I add the Path to a Canvas and use the Path.RenderTransform to rotate it through 45 degrees (so that is appears on the Canvas more like an x shape)
>>Now I want to create a new Path from this Path that gives the same appearance - but without using a Transform......
>>(Well, not quite true: I could use a Transform - but the bounds of the new Path need to be relative to the Canvas)
>>
>>The above is a simple example - the actual solution will need to work with Paths using more complex Transforms
>>
>>Any suggestions?

Don't know if this will help much, but here's an example of doing something similar in XAML:

What I do is transform a DrawingGroup instead of transforming the geometry.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <!-- 
	DrawingGroup
	  DrawingGroup.Children
		  GeometryDrawing

  ***Takes Geometry as a value			
	DoubleAnimationUsingPath.PathGeometry 
  DrawingGroup.ClipGeometry 
  GeometryDrawing.Geometry 
  Path.Data 
  UIElement.Clip 
	-->

  <SolidColorBrush x:Key="ContactsShirtBrush"      Color="#ffffffff" />
  <SolidColorBrush x:Key="ContactsJacketBrush"     Color="#ff357cff" />

  <LinearGradientBrush x:Key="ContactsHeadBrush" MappingMode="Absolute" StartPoint="287.208984,225.969238" EndPoint="287.208984,235.292969">
    <LinearGradientBrush.GradientStops>
      <GradientStop Offset="0.000000" Color="#ffe3bb95"/>
      <GradientStop Offset="0.209040" Color="#ffe7a976"/>
      <GradientStop Offset="1.000000" Color="#ffea9657"/>
    </LinearGradientBrush.GradientStops>
    <LinearGradientBrush.Transform>
      <MatrixTransform Matrix="1.000000,0.000000,-0.000000,-1.000000,-279.500000,236.500000" />
    </LinearGradientBrush.Transform>
  </LinearGradientBrush>
			
  <Pen x:Key="ContactsBodyPen" DashCap="Flat" Thickness="0.554446" Brush="#ff1e5995" MiterLimit="1.000000" />
  <Pen x:Key="ContactsHeadPen" DashCap="Flat" Thickness="0.362068" Brush="#ffd49657" MiterLimit="1.000000" />
			
  <PathGeometry x:Key="ContactsShirtPath"        Figures="M 10.473633,15.442383 L 5.522461,15.442383 L 5.522461,9.950195 L 10.473633,9.950195 L 10.473633,15.442383 Z" />
  <PathGeometry x:Key="ContactsHeadPath"         Figures="M 12.371094,5.868652 C 12.371094,8.443359 10.284180,10.530762 7.709961,10.530762 C 5.134766,10.530762 3.047852,8.443359 3.047852,5.868652 C 3.047852,3.293945 5.134766,1.207031 7.709961,1.207031 C 10.284180,1.207031 12.371094,3.293945 12.371094,5.868652 Z" />
  <PathGeometry x:Key="ContactsLeftSholderPath"  Figures="M 3.160156,10.143555 C 7.221680,9.195801 5.445313,10.221191 6.295898,13.470215 L 7.214844,15.182129 L 0.414063,15.191406 L 0.433594,14.739746 C 0.333984,11.473145 1.806641,10.459473 3.160156,10.143555 Z" />
  <PathGeometry x:Key="ContactsRightSholderPath" Figures="M 12.794922,10.143555 C 8.733398,9.195801 10.628906,10.221191 9.777344,13.470215 L 8.607422,15.182129 L 15.541016,15.191406 L 15.521484,14.739746 C 15.621094,11.473145 14.148438,10.459473 12.794922,10.143555 Z" />

  <DrawingCollection x:Key="dwgContactPaths">
    <GeometryDrawing Geometry="{StaticResource ContactsShirtPath}" 
		                 Brush="{StaticResource ContactsShirtBrush}" />
    <GeometryDrawing Geometry="{StaticResource ContactsHeadPath}" 
			               Pen="{StaticResource ContactsHeadPen}"  
		                 Brush="{StaticResource ContactsHeadBrush}" />
    <GeometryDrawing Geometry="{StaticResource ContactsLeftSholderPath}" 
			               Pen="{StaticResource ContactsBodyPen}"  
		                 Brush="{StaticResource ContactsJacketBrush}" />
    <GeometryDrawing Geometry="{StaticResource ContactsRightSholderPath}" 
	                   Pen="{StaticResource ContactsBodyPen}"  
		                 Brush="{StaticResource ContactsJacketBrush}" />
  </DrawingCollection>

  <DrawingGroup x:Key="dwgContact"    Children="{StaticResource dwgContactPaths}" />
  <DrawingBrush x:Key="vbrushContact" Drawing="{StaticResource dwgContact}" />
  <DrawingImage x:Key="vimgContact"   Drawing="{StaticResource dwgContact}" />

  <DrawingGroup x:Key="dwgContacts">
    <DrawingGroup Children="{StaticResource dwgContactPaths}" >
      <DrawingGroup.Transform>
        <TransformGroup>
          <ScaleTransform ScaleX="0.5" ScaleY="0.5" />
        </TransformGroup>			  
      </DrawingGroup.Transform>
    </DrawingGroup>
    <DrawingGroup Children="{StaticResource dwgContactPaths}">
      <DrawingGroup.Transform>
        <TransformGroup>
          <ScaleTransform ScaleX="0.5" ScaleY="0.5" />
          <TranslateTransform  X="4" Y="3" />
        </TransformGroup>			  
      </DrawingGroup.Transform>
    </DrawingGroup>
  </DrawingGroup>
  <DrawingImage x:Key="vimgContacts"   Drawing="{StaticResource dwgContacts}" />
  <DrawingBrush x:Key="vbrushContacts" Drawing="{StaticResource dwgContacts}" />
</ResourceDictionary>
Usage:
<Image Margin="2,0,0,0" 
           Name="image1" 
           Grid.Column="0"
           Stretch="Fill" 
           HorizontalAlignment="Left" 
           Width="16"  
           Height="16" 
           VerticalAlignment="Center" 
           Source="{StaticResource vimgContacts}" />
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform