This is a migrated thread and some comments may be shown as answers.

Binding UriImageProvider to something in memory

1 Answer 104 Views
Map
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 02 Dec 2011, 12:20 AM
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

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 06 Dec 2011, 10:01 AM
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 >>

Tags
Map
Asked by
Seth
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or