Reputation: 85835
I want to have a couple images in my phone application. However I don't know where to store them. Like I add them to my VS project but of course the image path is the path on my harddrive.
So is like special folder in windows mobile where I store it. Like if I transfer my application to the phone I am going to have to stick this image somewhere. It also has to be a place where it can't be deleted by the user.
Thanks
Upvotes: 1
Views: 1762
Reputation: 375
I suggest that keep all images in sub-directory (i.e. images) under Application installed folder
e.g.: MyApp\Images
When you debug the project, images will not copy into Debug or Release folder, you have to copy paste them manually (Or as Matt mentioned, Select an image file from solution explorer and in Properties, Select "Copy To Output Directory" as "Copy always" or "Copy if newer". It will also keep the directory structure) and then copy whole Debug or Release folder into the device.
You can specify path of images in your application like:
// Get full application path
String full_path = System.Reflection.Assembly.GetCallingAssembly().GetName().CodeBase;
if (full_path.LastIndexOf("\\") != -1)
{
// Take away application name from full path and return current directory name
String directory_path = full_path.Substring(0, full_path.LastIndexOf("\\") + 1);
// Specify images directory
String directoryImages = directory_path + "images";
}
If you want to create an installer, then add folder and images into the installer (Or Right click on "Application Folder" under File System of CAB Project, Select "Add>Project" Output and choose "Content Files" and Press OK). When you will install application using .CAB file, it will install files and keep same directory structure of file (which are marked as "Copy always" or "Copy if newer").
Upvotes: 1
Reputation: 9634
Either You add all images as resource and Build it, or keep separately in programme files and reffer all images from there, ususally users doesnt delete content from programe files.
here is the steps to add image as resource,
1) Create a new C# Project 2) Go to project properties 3) Go to resource tab 4)Click on Dropdown button of Add Resource 5)Select Add existing File 6)Choose the image from Your system. this leads to addition of images to your project resources.
Then in order to use the image just follow,The following syntax
YourProjectNameSpace.Properties.Resources.ImageFileName
here is the sample code of displaying the image taken from the Project resource,
Bitmap MyBitmap = new Bitmap(Delete1.Properties.Resources.Greenish_Logon_Vista_by_ralph1975);
pictureBox1.Image = MyBitmap;
i hope this helps..
Upvotes: 1