BitmapImage setzen



  • hallo

    ich versuche im code ein bitmapimage zu füllen und zwar so:

    CurrentToolImage = new BitmapImage(new Uri(@"\\Views\\Icons\\one_tile_tool.png", UriKind.Relative));

    leider klappt das nicht. das heißt, dass der entsprechende button ohne image bleibt. wenn ich mir das currenttoolimaage genauer ansehe, steht dort bei metadata folgendes:

    Metadata = 'CurrentToolImage.Metadata' threw an exception of type 'System.NotSupportedException'

    was mache ich falsch?

    chrische



  • Versuchs mal so:

    var CurrentToolImage = new BitmapImage();
    CurrentToolImage.BeginInit();
    CurrentToolImage.UriSource = new Uri("pack://application:,,,/Common;component/Something/Views/Icons/one_tile_tool.png", UriKind.RelativeOrAbsolute);
    //CurrentToolImage.DecodePixelHeight = 50;
    //CurrentToolImage.DecodePixelWidth = 50;
    CurrentToolImage.EndInit();
    

    //Dazu:
    Siehe: http://msdn.microsoft.com/en-us/library/ms602473(v=vs.95).aspx
    Beim Uri Konstruktor wird nicht jedes Format akzeptiert:

    The format-specific filename extensions such as .png are not necessarily required to be in the URI naming, but if the retrieved file is not determined to be a valid image format, a runtime exception is thrown.



  • hallo

    ich habe jetzt deinen weg genommen und dazu noch absolute pfade probiert. nun klappt es.

    chrische


Anmelden zum Antworten