Binding UriImageProvider to something in memory

2 posts, 0 answers
  1. Seth
    Seth avatar
    25 posts
    Member since:
    Jan 2009

    Posted 01 Dec 2011 Link to this post

    Hello,

    I have another UriImageProvider question. I have a series of images that my user can select from (via a drop down). When they select the image they want, I need my RadMap's UriImageProvider to grab the currently selected image information and display the image. Preferably, I would use the Byte Array that I have in memory to build the image on the fly and pass it to the provider. Worse case, I can write it to disk but I would rather avoid this. I can't seem to see a way to do this with Uri="{Binding...}". Any examples out there on how to dynamically change the Uri of the UriImageProvider?


    Cheers,
    Seth
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 06 Dec 2011 Link to this post

    Hi Seth,

    You can't use UriImageProvider to show images from the byte array. The UriImageProvider.URI property gets or sets image URI i.e. address of the image file somewhere. To show new image you should change UriImageProvider.URI property. For example, following code loads image from the file system to the UriImageProvider:

    private void LoadImageToProviderProvider()
    {
        OpenFileDialog fileDialog = new OpenFileDialog();
        fileDialog.Title = "Load image.";
        fileDialog.Filter = "Images (*.png,*.jpg)|*.png;*.jpg|All Files (*.*)|*.*";
        fileDialog.DefaultExt = "png";
        if (fileDialog.ShowDialog() == true)
        {
            Uri uri = new Uri(fileDialog.FileName);
            BitmapImage image = new BitmapImage(uri);
     
            Size geoSize = this.radMap.GetGeoSize(new Location(0, 0), new Size(image.PixelWidth, image.PixelHeight));
     
            UriImageProvider provider = this.radMap.Providers[1] as UriImageProvider;
            provider.Uri = uri;
     
            LocationRect view = new LocationRect(
                new Location(0, 0),
                new Location(-geoSize.Height, geoSize.Width));
            view.MapControl = this.radMap;
            provider.GeoBounds = view;
            this.radMap.GeoBounds = view;
            this.radMap.MinZoomLevel = view.ZoomLevel;
            this.radMap.SetView(view);
        }
    }
     

    All the best,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top