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].
Related
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”}
I am writing a simple game for my course work. The application contains many pictureboxes with no images inside them. I also have a directory with needed pictures in the Visual Studio project debug folder. I need to put the pictures' paths into an array in my program to then randomly insert them into pictureboxes.
The problem is I don't know how it would work on another computer, so I can't organize all the things. The game must be launched without using Visual Studio there, only exe file. Should I first make the installation setup of my unfinished program, or something like this, and then place the application with resources somewhere on disk to know where all my pictures would be on any computer? And then maybe I could determine the exact path where I would take all the pictures and put them into the array. Or vice versa... I'm totally confused with this.
Here what I use to fill the array:
string[] spritePaths = Directory.GetFiles(/*paths*/);
Is it possible for you to distribute the pictures in a folder with the .exe file? If so, you could use a relative path to get all of the pictures.
string[] spritePaths = Directory.GetFiles("pictureFolder");
As DangerZone suggests, you could also add your images as embedded resources.
https://support.microsoft.com/en-us/help/319292/how-to-embed-and-access-resources-by-using-visual-c
Here are a few options:
Specify the path to the folder of images as a command line argument. Then you can launch it from CMD, or create a shortcut and specify the arguments there.
Add a TextBox for the user to enter the path to the images.
Add a browse button or menu button and allow the user to search for the folder using a dialog.
Use a predefined location, such as an images folder next to the exe.
i have a picture box in my win forms app. the question is, how can i make the image load from a directory within that application,
for example, i have a program and it lies under Debug directory. Now i have an image located under Debug/source/images/logo.png. I dont want to make use of resources file (embedded within the assembly)
How can i point it towards that path, instead of getting the image/picture from the local resources file.
Try this
String.Format(#"{0}\myDesiredPath\MyFile.MyExtension",System.Reflection.Assembly.GetExecutingAssembly().Location);
There are a number of ways to do this, you can use the ImageLocation property or the Load method to specify the path just take a look at the documentation here
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.