Skip to main content

Microsoft Silverlight

Answered Question How to get Image Url(Path) from ImageSourceRSS Feed

(0)

kranthi_015
kranthi_015

Member

Member

12 points

3 Posts

How to get Image Url(Path) from ImageSource

Hi,

I have a ImageBrush and have given ImageSource as Bitmap, now i want to get the ImageUrl of the ImageSource.

My image source is

args.ImageSource = ((Path)sender).Fill.GetValue(ImageBrush.ImageSourceProperty) as BitmapImage;

but, I am not able to get the Image url of the args.ImageSource.

 

 Thanks in advance,

Kranthi

HarshBardhan
HarshBar...

Star

Star

9908 points

1,719 Posts

Answered Question

Re: How to get Image Url(Path) from ImageSource

Hi,

Try with this code.

You can Minimize this one..

//Page.Xaml

<Grid x:Name="LayoutRoot" Background="White">

 

<Rectangle Height="100" MouseEnter="Rectangle_MouseEnter">

 

<Rectangle.Fill>

<ImageBrush x:Name="myBrush" ImageSource="1.jpg"></ImageBrush>

</Rectangle.Fill>

</Rectangle>

</Grid>

//Page.xaml.cs

private void Rectangle_MouseEnter(object sender, MouseEventArgs e)

{

Rectangle rectobj = sender as Rectangle;

ImageBrush imgBrush = rectobj.Fill as ImageBrush;

string a = ((System.Windows.Media.Imaging.BitmapImage)(((imgBrush)).ImageSource)).UriSource.ToString();

Image img = new Image();

img.Source = new BitmapImage(new Uri(a, UriKind.RelativeOrAbsolute));

LayoutRoot.Children.Add(img);

}

Mark as answer if this post answered your question.

Harsh Bardhan

kranthi_015
kranthi_015

Member

Member

12 points

3 Posts

Re: How to get Image Url(Path) from ImageSource

This is what exactly i needSmile....

thanks a lot HarshBardhan

balukr54
balukr54

Member

Member

124 points

143 Posts

Re: How to get Image Url(Path) from ImageSource

Hi Harsh
How can i change the image in imagebrush dynamically
this is my code

<Path x:Name="pathTest" Margin="77,37,198.5,138.5" Stretch="Fill" Stroke="#FF000000" Data="M81,39 L81,161 L200.5,158.5 L199.00624,39.5 L77.51458,37.5">
            <Path.Fill>
                <ImageBrush x:Name="myBrush" ImageSource="images/22.jpg"></ImageBrush>//this have to refreshed //dynamicaaly.
            </Path.Fill>
        </Path>
        <Canvas Margin="189,200,8,68">
        <RadioButton x:Name="rb1" Content="Image1" Checked="rb1_Checked"/>
        <RadioButton x:Name="rb2" Content="Image2" Checked="rb2_Checked" Canvas.Left="68"/>
        <RadioButton x:Name="rb3" Content="Image3" Checked="rb3_Checked" Canvas.Left="136"/>
        </Canvas>

private void rb1_Checked(object sender, RoutedEventArgs e)
        {
          //how can i change the image?? i need to chane the image of(myBrush)and update it with new image
        }
private void rb2_Checked(object sender, RoutedEventArgs e)
        {
          // i need to chane the image of(myBrush)and update it with new image
        }
private void rb3_Checked(object sender, RoutedEventArgs e)
        {
         // i need to chane the image of(myBrush)and update it with new image
        }

Thanks
balu

balukr54
balukr54

Member

Member

124 points

143 Posts

Re: How to get Image Url(Path) from ImageSource

Hi

i got the solution

ImageBrush imgBrush = pathTest.Fill as ImageBrush;

imgBrush.ImageSource = new BitmapImage(new Uri(url, UriKind.Relative));

spbAngel
spbAngel

Member

Member

2 points

1 Posts

Re: How to get Image Url(Path) from ImageSource

 

string a = ((System.Windows.Media.Imaging.BitmapImage)(((imgBrush)).ImageSource)).UriSource.ToString();
This line throw exception, because type of imgBrush.ImageSource is BitmapFrameDecode

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities