Load images to Image from path outside of project

Hi , I hope some one can help me.
I have somewhere in computer folder with .png images.
I need to show those images in Images containers in grid in MainWindow.xaml.  from code.
Right now I can only load images saved in project directory and cannot find how to use path to images to load them as source
There is not an option to move those images to project directory.
LVL 1
mastiSoftAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
Are you trying to build an image gallery or something similar? You can use image path directly to load the images in the image control.
0
mastiSoftAuthor Commented:
I don't know if I can call it is gallery. I need to show recent open files as images using path to folder where small images was created when file was loaded to application.
0
Chinmay PatelChief Technical NinjaCommented:
Perfect. All you need is programmatically get the path of the folder build a list<string> and bind it to a list of image controls data source.
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

mastiSoftAuthor Commented:
I added image to grid and named it as RecF1.  I have path to the .png file  ImagPathRecFiles.
 RecF1.Source =new Uri(@"ImagPathRecFiles", UriKind.Relative); gives error
0
Chinmay PatelChief Technical NinjaCommented:
Hi mastiSoft,

I think there is something else is going on. And please :) If you save it gives an error - I will have to be omniscient to know what error it is giving. Always give the details on error. You are free to scrub any sensitive information for example, class name, namespace, credentials etc.

Alright, so I tried using declarative path
<Image Source="C:\Users\Chinmay\Desktop\about.png" HorizontalAlignment="Stretch" 
    Stretch="Fill" VerticalAlignment="Stretch" Grid.Row="0" Grid.RowSpan="5" />

Open in new window


And the result is:
WPF Image Source - Non-project path
I think you should try UrlKind.Absolute, Relative will search for the image basis your App's root folder.

Regards,
Chinmay.
0
mastiSoftAuthor Commented:
thank you for trying to help. I don't have problems to access source of image from xaml, what I try is do it from code
0
Chinmay PatelChief Technical NinjaCommented:
In that case,
this.BgImage.Source = new BitmapImage(new Uri((@"C:\Users\Chinmay\Desktop\about.png")));

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mastiSoftAuthor Commented:
thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WPF

From novice to tech pro — start learning today.