简体   繁体   中英

Assign Uri to image source

i have a multiple projects as shown in figure , and i'm working on addpath.cs i assign the image source as follows :

Image image = new Image();
image.Source = new BitmapImage(new Uri("images/arrow.jpg", UriKind.Relative));

and when i use the following :

rt.CenterX = image.Width / 2;
rt.CenterY = image.Height / 2;

the value of width and height are Nan, so i guess there is wrong in the uri assigned to the image source ,or something else?

在此处输入图片说明

Use following code snippet:

var logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new Uri("pack://application:,,,/YOURAPP;component/images/arrow.jpg");
logo.EndInit();
rt.CenterX = logo.Width / 2.0;
rt.CenterY = logo.Height / 2.0;

Don't forget to replace YOURAPP with the name of your project!

i found the solution the images folder should be placed in 'client bin' folder that is located in the website directory . thank you all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM