@@ -22,33 +22,44 @@ public class ImageShape : Shape
2222
2323 public ImageShape ( SVG svg , XmlNode node ) : base ( svg , node )
2424 {
25- this . X = XmlUtil . AttrValue ( node , "x" , 0 , svg . Size . Width ) ;
26- this . Y = XmlUtil . AttrValue ( node , "y" , 0 , svg . Size . Height ) ;
27- this . Width = XmlUtil . AttrValue ( node , "width" , 0 , svg . Size . Width ) ;
25+ this . X = XmlUtil . AttrValue ( node , "x" , 0 , svg . Size . Width ) ;
26+ this . Y = XmlUtil . AttrValue ( node , "y" , 0 , svg . Size . Height ) ;
27+ this . Width = XmlUtil . AttrValue ( node , "width" , 0 , svg . Size . Width ) ;
2828 this . Height = XmlUtil . AttrValue ( node , "height" , 0 , svg . Size . Height ) ;
2929 string hRef = XmlUtil . AttrValue ( node , "xlink:href" , string . Empty ) ;
3030 if ( hRef . Length > 0 )
3131 {
3232 try
3333 {
34- BitmapImage b = new BitmapImage ( ) ;
35- b . BeginInit ( ) ;
36- if ( hRef . StartsWith ( "data:image/png;base64" ) )
34+ Stream imageStream = null ;
35+ if ( hRef . StartsWith ( "data:image/png;base64" , StringComparison . OrdinalIgnoreCase ) )
3736 {
38- b . StreamSource = new MemoryStream ( Convert . FromBase64String ( hRef . Substring ( "data:image/png;base64," . Length ) ) ) ;
37+ var embeddedImage = hRef . Substring ( "data:image/png;base64," . Length ) ;
38+ if ( ! string . IsNullOrWhiteSpace ( embeddedImage ) )
39+ {
40+ imageStream = new MemoryStream ( Convert . FromBase64String ( embeddedImage ) ) ;
41+ }
3942 }
4043 else
4144 {
4245 if ( svg . ExternalFileLoader != null )
43- b . StreamSource = svg . ExternalFileLoader . LoadFile ( hRef , svg . Filename ) ;
46+ {
47+ imageStream = svg . ExternalFileLoader . LoadFile ( hRef , svg . Filename ) ;
48+ }
4449 }
50+ if ( imageStream != null )
51+ {
52+ BitmapImage b = new BitmapImage ( ) ;
53+ b . BeginInit ( ) ;
54+ b . StreamSource = imageStream ;
55+ b . EndInit ( ) ;
4556
46- b . EndInit ( ) ;
47- this . ImageSource = b ;
57+ this . ImageSource = b ;
58+ }
4859 }
4960 catch ( Exception ex )
5061 {
51- Trace . TraceError ( ex . Message ) ;
62+ Trace . TraceError ( ex . ToString ( ) ) ;
5263 }
5364 }
5465 }
0 commit comments