problem with new version

48 views
Skip to first unread message

Wpf Help

unread,
Apr 16, 2009, 3:34:23 AM4/16/09
to WPF Graphics Site group
Hi,

Failed object initialization (ISupportInitialize.EndInit). Property
'UriSource' or property 'StreamSource' must be set. Error at object
'System.Windows.Media.Imaging.BitmapImage

exception error occur when i try to clone(copy->Paste) the viewbox
that read using readersvg 2.3, so please check the sample to reproduce
the issue



<Window x:Class="Transfom.Window4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window4" Height="300" Width="300">
<Grid>
<Canvas Name="canvas" Background="AntiqueWhite" >
</Canvas>
</Grid>
</Window>









public partial class Window4 : Window
{
public Window4()
{
InitializeComponent();
load();
canvas.PreviewMouseLeftButtonDown += new
MouseButtonEventHandler(canvas_PreviewMouseLeftButtonDown);

}

void canvas_PreviewMouseLeftButtonDown(object sender,
MouseButtonEventArgs e)
{
string xaml = System.Windows.Markup.XamlWriter.Save
(canvas.Children[0]);

using (System.IO.MemoryStream stream = new
System.IO.MemoryStream(xaml.Length))
{
using (System.IO.StreamWriter sw = new
System.IO.StreamWriter(stream))
{
sw.Write(xaml);
sw.Flush();
stream.Seek(0, System.IO.SeekOrigin.Begin);
UIElement uie =
System.Windows.Markup.XamlReader.Load(stream) as UIElement;
}
}
}
public void load()
{
Ab2d.ReaderSvg myreader = new Ab2d.ReaderSvg();

Viewbox vb = myreader.Read(@"C:\Documents and Settings
\User1\Desktop\LDS Export\15-04-09\1.svg");

string xaml = System.Windows.Markup.XamlWriter.Save(vb);

canvas.Children.Add(vb);
}

}




Wpfhelp

unread,
Apr 16, 2009, 4:33:18 AM4/16/09
to WPF Graphics Site group
Check with the attached svg file
1.svg

Andrej Benedik

unread,
Apr 17, 2009, 2:47:53 AM4/17/09
to wpf-gr...@googlegroups.com
Hi,

I have checked your code and find out that it has nothing to do with ReaderSvg.

The problem is that the xaml produced with XamlWriter.Save does not write the Image's source correctly.
To avoid this problem, use the GetXaml method of the new ReaderSvg and use the code I have already written to you for your "problem with getxaml" post.

This way the images in svg file will be saved to disk and the xaml returned by GetXaml will contain correct paths to the images.

Andrej

Wpf Help

unread,
Apr 17, 2009, 4:36:49 AM4/17/09
to WPF Graphics Site group
But GetXaml always return streamgeometry...

i need all UiElements in my application canvas, is it anyway to get
list of all uielements,

On Apr 17, 11:47 am, Andrej Benedik <abene...@gmail.com> wrote:
> Hi,
>
> I have checked your code and find out that it has nothing to do with
> ReaderSvg.
>
> The problem is that the xaml produced with XamlWriter.Save does not write
> the Image's source correctly.
> To avoid this problem, use the GetXaml method of the new ReaderSvg and use
> the code I have already written to you for your "problem with getxaml" post.
>
> This way the images in svg file will be saved to disk and the xaml returned
> by GetXaml will contain correct paths to the images.
>
> Andrej
>

Wpf Help

unread,
Apr 17, 2009, 5:18:39 AM4/17/09
to WPF Graphics Site group
Hi Andrej,

check this sample you will get all the problems

Thanks

public partial class Window5 : Window
{
public Window5()
{
InitializeComponent();
LoadViewbox();
//LoadSvg();
canvas.PreviewMouseLeftButtonDown += new
MouseButtonEventHandler(canvas_PreviewMouseLeftButtonDown);
}

void canvas_PreviewMouseLeftButtonDown(object sender,
MouseButtonEventArgs e)
{
for(int i=0;i<canvas.Children.Count;i++)
{
string xaml = System.Windows.Markup.XamlWriter.Save
(canvas.Children[i]);

using (System.IO.MemoryStream stream = new
System.IO.MemoryStream(xaml.Length))
{
using (System.IO.StreamWriter sw = new
System.IO.StreamWriter(stream))
{
sw.Write(xaml);
sw.Flush();
stream.Seek(0, System.IO.SeekOrigin.Begin);

UIElement uie =
System.Windows.Markup.XamlReader.Load(stream) as UIElement;
MessageBox.Show(uie.ToString());
MessageBox.Show("Sucess");
}
}

}
}

public void LoadViewbox()
{
Viewbox viewbox = new Viewbox();
viewbox.Stretch = Stretch.Uniform;
Canvas vieCanvas = new Canvas();
vieCanvas.Width = vieCanvas.Height = 338.5;
Canvas canCanvas = new Canvas();
Path path = new Path();
path.Fill = Brushes.White;
path.Data = StreamGeometry.Parse
("M137.250,227.250L474.750,227.250L474.750,564.750L137.250,564.750L137.250,227.250z");

Path path1 = new Path();
path1.Data = StreamGeometry.Parse
("M208.500,316.500L400.500,316.500L400.500,460.500L208.500,460.500L208.500,316.500z");

ImageBrush imgbr = new ImageBrush();
imgbr.ViewportUnits = BrushMappingMode.Absolute;
imgbr.Viewport = new Rect(0, 0, 800, 600);
imgbr.TileMode = TileMode.Tile;

BitmapImage bitImg = new BitmapImage();
bitImg.DecodePixelHeight = 600;
bitImg.DecodePixelWidth = 800;

bitImg.BeginInit();
bitImg.CacheOption = BitmapCacheOption.OnLoad;
bitImg.UriSource = new Uri(@"C:\Documents and Settings
\User1\Desktop\LDS Export\15-04-09\2.jpg");
bitImg.EndInit();

imgbr.ImageSource = bitImg;


path1.Fill = imgbr;

canCanvas.Children.Add(path);
canCanvas.Children.Add(path1);

vieCanvas.Children.Add(canCanvas);

viewbox.Child = vieCanvas;
canvas.Children.Add(viewbox);

/// its working perfectly why your tool is only giving bug

// <!-- Converted from svg with Ab2d.ReaderSvg.
See www.wpf-graphics.com for more WPF tools. -->
//<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/
xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/
xaml" Stretch="Uniform">
// <Canvas Width="338.5" Height="338.5">
// <Canvas Canvas.Left="-136.75"
Canvas.Top="-226.75">
// <Path Fill="White"
Data="M137.250,227.250L474.750,227.250L474.750,564.750L137.250,564.750L137.250,227.250z"/
>
// <Path
Data="M208.500,316.500L400.500,316.500L400.500,460.500L208.500,460.500L208.500,316.500z">
// <Path.Fill>
// <ImageBrush ViewportUnits="Absolute"
Viewport="0,0,800,600" TileMode="Tile">
// <ImageBrush.ImageSource>
// <BitmapImage
DecodePixelWidth="800" DecodePixelHeight="600" UriSource="C:\Documents
and Settings\User1\Desktop\LDS Export\15-04-09\2.jpg"/>
// </ImageBrush.ImageSource>
// </ImageBrush>
// </Path.Fill>
// </Path>
// </Canvas>
// </Canvas>
//</Viewbox>

}
public void LoadSvg()
{
Ab2d.ReaderSvg myreadersvg;
myreadersvg = new Ab2d.ReaderSvg();

Viewbox vb = myreadersvg.Read(@"C:\Documents and Settings
\User1\Desktop\LDS Export\15-04-09\1.svg");
canvas.Children.Add(vb);
string xaml = System.Windows.Markup.XamlWriter.Save(vb);
Reply all
Reply to author
Forward
0 new messages