0

WPF アプリケーションからのパス データの次のスニペットがあります。

<Path
    Data="F1 M 23.533,16.758 C 23.673,16.305 24.033,15.094 24.611,13.125 C 24.751,12.609 25.111,11.586 25.689,10.055 C 26.267,8.477 26.728,7.211 27.072,6.258 C 26.056,6.930 25.024,7.820 23.978,8.930 C 20.290,12.899 17.688,16.141 16.173,18.656 C 16.751,18.516 17.993,18.164 19.900,17.602 C 20.447,17.446 21.658,17.165 23.533,16.758 Z M 22.876,19.289 C 19.329,19.992 16.361,20.821 13.970,21.773 C 12.532,23.883 10.955,26.414 9.236,29.367 L 7.994,31.547 C 7.774,31.938 7.439,32.500 6.986,33.234 C 6.486,34.093 5.963,34.523 5.416,34.523 C 5.119,34.523 4.869,34.406 4.666,34.172 C 4.463,33.969 4.361,33.742 4.361,33.492 C 4.361,33.055 4.947,31.813 6.119,29.766 C 6.760,28.656 7.728,27.086 9.025,25.055 C 9.525,24.273 9.923,23.633 10.220,23.133 C 9.283,23.399 8.423,23.704 7.642,24.047 C 7.267,24.219 6.955,24.305 6.705,24.305 C 6.392,24.305 6.150,24.164 5.978,23.883 C 5.853,23.711 5.791,23.508 5.791,23.273 C 5.791,22.743 5.978,22.368 6.353,22.148 C 6.962,21.773 8.056,21.344 9.634,20.859 C 10.806,20.484 11.735,20.141 12.423,19.828 C 12.751,19.422 13.610,18.227 15.001,16.242 C 15.595,15.383 17.283,13.352 20.064,10.148 C 22.064,7.805 24.126,5.625 26.251,3.609 C 27.485,2.422 28.431,1.828 29.087,1.828 C 29.494,1.828 29.845,1.992 30.142,2.320 C 30.392,2.617 30.517,2.945 30.517,3.305 C 30.517,3.742 30.298,4.508 29.861,5.602 C 29.111,7.523 28.392,9.578 27.705,11.766 C 27.110,13.703 26.712,15.188 26.509,16.219 C 26.791,16.219 26.978,16.211 27.072,16.195 C 27.525,16.180 27.900,16.172 28.197,16.172 C 29.103,16.172 29.556,16.516 29.556,17.203 C 29.556,17.500 29.458,17.793 29.263,18.082 C 29.067,18.372 28.845,18.547 28.595,18.609 C 28.501,18.641 28.244,18.656 27.822,18.656 C 26.931,18.656 26.267,18.711 25.830,18.820 C 25.455,19.930 24.860,22.766 24.048,27.328 C 23.626,30.360 23.423,32.219 23.439,32.906 C 23.439,34.031 23.103,34.594 22.431,34.594 C 21.900,34.594 21.485,34.320 21.189,33.773 C 20.970,33.398 20.861,32.891 20.861,32.250 C 20.861,30.094 21.244,27.188 22.009,23.531 C 22.399,21.688 22.689,20.273 22.876,19.289 Z"
    Fill="#ff262324"
    Stroke="#ff262324"
    StrokeMiterLimit="1.0"
    StrokeThickness="0.3" />

私が疑問に思っているのは、このスニペットを何らかの方法で変換して、WinForm アプリケーションに表示できるかどうかです。または、WPF パス データを GDI+ に変換できるライブラリはありますか? または、このパス データを PNG や JPEG のように変換するプログラムがある場合でも、

4

1 に答える 1

0

コントロールをビットマップにレンダリングすることは可能です。これに関するチュートリアルはたくさんあります。

次の例は、ここから抜粋したものです。

 /// <summary>
    /// Extension Methods for the System.Windows.Media.Visual Class
    /// </summary>
    public static class VisualExtensions
    {
        /// <summary>
        /// Returns the contents of a WPF Visual as a Bitmap in PNG format.
        /// </summary>
        /// <param name="visual">A WPF Visual.</param>
        /// <returns>A GDI+ System.Drawing.Bitmap.</returns>
        public static Bitmap PngBitmap(this Visual visual)
        {
            // Get height and width
            int height = (int)(double)visual.GetValue(FrameworkElement.ActualWidthProperty);
            int width = (int)(double)visual.GetValue(FrameworkElement.ActualHeightProperty);

            // Render
            RenderTargetBitmap rtb =
                new RenderTargetBitmap(
                    height,
                    width,
                    96,
                    96,
                    PixelFormats.Default);
            rtb.Render(visual);

            // Encode
            PngBitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(rtb));
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            encoder.Save(stream);

            // Create Bitmap
            Bitmap bmp = new Bitmap(stream);
            stream.Close();

            return bmp;
        }

        /// <summary>
        /// Returns the contents of a WPF Visual as a BitmapSource, e.g.
        /// for binding to an Image control.
        /// </summary>
        /// <param name="visual">A WPF Visual.</param>
        /// <returns>A set of pixels.</returns>
        public static BitmapSource BitmapSource(this Visual visual)
        {
            Bitmap bmp = visual.PngBitmap();
            IntPtr hBitmap = bmp.GetHbitmap();
            BitmapSizeOptions sizeOptions = BitmapSizeOptions.FromEmptyOptions();
            return Imaging.CreateBitmapSourceFromHBitmap(
                                hBitmap,
                                IntPtr.Zero,
                                Int32Rect.Empty,
                                sizeOptions);
        }
    }
}
于 2012-06-15T15:53:39.640 に答える