locked
In win8 store app(C#) ,how can i show the SVG file in the Rectangle?

    Question

  •  I have try with the following code, But  still can not show the SVG file?Please tell me how can I?

                            Rectangle rectangle = new Rectangle();
                            rectangle.Width = imageInfo.Rectangle.Width;
                            rectangle.Height = imageInfo.Rectangle.Height;
                            rectangle.Stretch = Stretch.Fill;
                            rectangle.Stroke = new SolidColorBrush(Color.FromArgb(0, 25, 25, 112));

                           ImageBrush imgBrush = new ImageBrush();
                                string imageSource = imageInfo.Src.Replace("\\", "/");
                                imageSource = imageSource.Replace("/./", "/");
                                imageSource = @"ms-appx:///" + imageSource;

                           

    try
                                {
                                    StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(imageSource));
                                    using (IRandomAccessStream fileStream = await file.OpenReadAsync())
                                    {
                                        // Set the image source to the selected bitmap
                                        BitmapImage bitmapImage = new BitmapImage();
                                        bitmapImage.SetSource(fileStream);
                                        imgBrush.ImageSource = bitmapImage;
                                        //imgBrush.
                                        rectangle.Fill = imgBrush;

                                    }
                                }
                                catch (Exception ex)
                                {
                                    //log.error(ex);
                                }

    Wednesday, July 09, 2014 6:58 AM

All replies

  • SVG is not a supported bitmap format. You can't load an SVG file into a BitmapImage.

    SVG is supported in HTML so you should be able to load it into a WebView control.

    Wednesday, July 09, 2014 7:05 AM
    Owner
  • Thanks for your answer.Please give me some sample code.
    • Marked as answer by wang xuesong Wednesday, July 09, 2014 7:19 AM
    • Unmarked as answer by wang xuesong Wednesday, July 09, 2014 7:20 AM
    Wednesday, July 09, 2014 7:16 AM
  • Please give me some sample about this
    Wednesday, July 09, 2014 7:27 AM
  • I have try the following code,But still can not show the file.Please tell me

    StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(imageSource));
                                    string strImagePage = @"<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE html><HTML  xmlns='http://www.w3.org/1999/xhtml' xmlns:epub='http://www.idpf.org/2007/ops' lang='ja' xml:lang='ja'><BODY><embed src='";
                                    strImagePage += file.Path + "' type='image/svg+xml' width='128' height='128' /></BODY></HTML>";
                                    WebView wv = new WebView();
                                    wv.Width = imageInfo.Rectangle.Width;
                                    wv.Height = imageInfo.Rectangle.Height;
                                    //wv.Navigate(new Uri(imageSource));
                                    //WebViewBrush vwb = new WebViewBrush();
                                    WebViewBrush vwb = new WebViewBrush();

                                    wv.NavigateToString(strImagePage);
                                    wv.UpdateLayout();

    Wednesday, July 09, 2014 8:11 AM
  • I have try the following code,But still can not show the file.but if create html file, then use the IE exploer open it, can show the SVG file .Please tell me the reason and the resolve of this problem?

    StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(imageSource));
                                    string strImagePage = @"<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE html><HTML  xmlns='http://www.w3.org/1999/xhtml' xmlns:epub='http://www.idpf.org/2007/ops' lang='ja' xml:lang='ja'><BODY><embed src='";
                                    strImagePage += file.Path + "' type='image/svg+xml' width='128' height='128' /></BODY></HTML>";
                                    WebView wv = new WebView();
                                    wv.Width = imageInfo.Rectangle.Width;
                                    wv.Height = imageInfo.Rectangle.Height;

                                    wv.NavigateToString(strImagePage);
     

    Thursday, July 10, 2014 5:56 AM
  • Please don't post duplicates of the same post. Please post your question once and keep all comments on the topic in the same thread. Time spent managing the multiple posts takes time that otherwise could have been spent answering.

    Thursday, July 10, 2014 7:59 PM
    Owner
  • Even the people of microsoft cant't resovle this question???I usally think that the people of microsoft is the excellentest in the world.In fact , I have make wong. It is a pity.
    Friday, July 11, 2014 3:30 AM
  • Please post your app to OneDrive, share the link here, and I'll look at it.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, July 16, 2014 3:54 PM
    Moderator