views:

385

answers:

2

Hi

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

+1  A: 

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..

Shadow
How do I do either one of these? Like I don't see a program file(unless I launch the emulator). So do I make a folder in VS and call it program file? I am not sure how to add them as resources either.
chobo2
Hey See I have edited the answer, i have mentioned the steps to add image to resource , and use the same
Shadow
Is there some disadvantage to use the resource way? Also would you have come up with the same way as "ZHZ" for keeping it in the programme files? Or is what he have another way to do it?
chobo2
The 'resource way' embeds the image files into the application, which prevents them from being removed from the filesystem by the users, however it does make the size of the application bigger, and if you want to just update/download a single image you will need to change the whole application.
Matt
Shadow
So what do I do? When you say deployed do you mean the on the phone? Or do yo mean I make this in VS? If I am just testing it on the emulator then where do Is stick the files so that path you gave would work? Also this cab file it create a folder and then you choose where it should install?
chobo2
Deploy means, it applicable to phones or emulator. it depends what you use for debugging.You need to deploy it from VS itself.Yes you create a folder at desired location of your wish and keep images there, give the specificpath it works.you can mentioned in .cab file were images should install and every thing.
Shadow
+1  A: 

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").

ZHS
If you change the 'Copy to Output Directory' property of your image file in your solution to 'Copy Always' or 'Copy If Newer' it will then deploy the file to your device or emulator when you deploy your application in visual studio
Matt
Matt, I have updated my post with your guidance :)
ZHS