I'm a beginner in terms of Xamarin (Forms) and face the following problem:
I've embedded some images into the project that I can also display in the app using:
<Image Source = 'Example.jpg'/> (XAML or C #)
My intention now is to insert a button that selects a random image from the list for viewing.
My idea was to use a foreach loop to sort the images in an internal List .
However, I would have to know for which path the images are stored.
In a Windows Forms application I would have tried to do that with the help of
DirectoryInfo folderpath = new DirectoryInfo(Environment.CurrentDirectory);
This works in Xamarin Forms but unfortunately not.
Incidentally, I saved these pictures in the solution under Android / Resources / drawable. As I said, I do not get it programmatically (in the C # code) to access it.
For help in this regard, I would be very grateful!
By default A Xamarin.Forms Application searches for image inside the Resources / drawable folder in Android and in Resources for iOS.
For example if you have 10 images to choose from, So what you can do is, name the images as 1.png, 2.png ... 10.png and store in both Android and iOS projects.
On the click on the button generate a random number between 1 to 10 and append ".png" to it and return to the image.
This would be an easier option.
Let me know if you have queries.
After putting your images in suitable Android/Resources/drawable and iOS/Resources folders, In C# code you can give image path like this:
var image = new Image{Source=“example.jpg”}
Related
My app has over 100 images. And how to I specify resources for other resolutions? I see both methods.
One by naming the folders scale-100 and other by naming each file with a suffix of scale 100. My app is developed in C#. And how do I test which image is taken?
For now my folder structure is
Assets -> Images-> scale-100 -> tab_icon_notes_clicked_1366.png
And in the code when I need to reference the image, I reference it like this.
("ms-appx:/Assets/Images/tab_icon_notes_clicked_1366.png");
So without using scale-100 in the image path, it is retrieving an image. I have another folder named as scale-140 in which the higher resolution of the same image is placed. But I cant figure out which image it is taking.. scale-100 or scale-140 ?
You can identify the System Display Scale Information by the Code below
var scaleInfo= DisplayProperties.ResolutionScale;
The system will take care of loading the correct Scale Images from the respective Scale Folders [100,140,180].
What I'm trying to do is have a collection of images stored in a media drive be dynamically changed once the user enters the images name in a text field. At the moment all I am able to do is load one singular image.
Is what I'd like to do even possible? If so, how can I go about doing it?
I'm extremely new to winform programming and my google searches haven't turned up much.
EDIT
Managed to fix the issue. The line of code I needed was as follows:
pictureBox1.Image = Image.FromFile("Image Location");
If you mean the Embedded Resource
The answer is you can't modify the image under the Local Resource
Here's a good explanation: how to edit a resource file
I am using the following tutorial to implement a gile upload system : file-upload-in-silverlight-a-simple-solution. I can get the images to upload into my Projects.Web folder. However, in my silverlight project I cannot get them to display. This is what I am using to display the image.
<Image Source="..//Theme/Theme2.jpg"/>
However, that fails to display anything although I am sure the path is correct.
If the image is in the ClientBin folder you can use: /images/theme/theme2.jpg
If the image is in the root of the web you can use: http://localhost:57097/images/theme/theme2.jpg
I am working on a file explorer using Silverlight OOB. I need a way to get and display the icon associated with each file in my application. Note, I only need to show the icons, I don´t need to open the files.
If I understood you right, you're building something like Windows Explorer and want to mimic its list view by showing the program icons right before their names.
I'm not sure whether OOB has access to the System.Drawing.Icon class, but if so, you can use the following code to get the icon for any given file:
Bitmap icon = System.Drawing.Icon.ExtractAssociatedIcon(filename).ToBitmap();
If not, the only way you can do it is by storing the icons for most common file formats in a dictionary and retrieving them from there based upon file extension.
I am creating a treeview which wil have folder images for directories and want to know if there is a way to access the system image list so that I can display the system default folder image.
Thx
Mark.
There is no out-of-the-box image list for the system images (they depend on things like the current visual theme). The entry for SHGetFileInfo at pinvoke.net has a code sample for extracting icons for files (and, I presume, folders). You can use that and dynamically populate an ImageList component to get the tree view display the appropriate icons.
To get the current system icons you should take a look into the registry at HKEY_CLASSES_ROOT\Folder\DefaultIcon. Here you'll find the path and position of the used folder icon.