WPF cannot set Build Action for added file [duplicate] - wpf

I would like to assign a BitmapImage from my Resources.resx to an Image.
Beforehand I saved a .png image to Resources.resx. This image is now located in "/Resources/logo.png".
After reading several SO posts and other articles I have this now:
logoImage.Source = new BitmapImage(new Uri(#"pack://application:,,,/Resources/logo.png"));
Unfortunately it doesn't work.
I don't know how to solve this.
I tried to replace the Pack-URI with the fullpath and it worked but I would like to use relative paths in order to use the same source on different machines on which the absolute path would be incorrect.
Can anyone help me out with this?

In order to make that Uri work, the file logo.png must be contained in a folder named "Resources" in your VS project (see first image), and its Build Action must be set to Resource (see second image).
This Resources folder is completely unrelated to Resources.resx. You may rename it to whatever you like.

Related

Where do i put mdl files for function SetModel

I am new in lua and gmod coding. I have already coded successfully a HUD's addons but i am stuck in another.
I want to create a new entity, and after reading lots of tutorial, i manage to do it but in game, the word ERROR appears in red when spawning, not the model. The server and the client are located on the same PC, for debugging considerations. I try to put mdl files on several folders without aby change.
I put mdl file in
addons/models/model.mdl
I think the client doesn't find the model file : do i need a workshop content even for testing ? Where do i put the files ?
Thanks.
I got it. When reusing existing MDL file, i must keep the original path for files.
That is, when opening mdl file, a path is writing at the begining. This path must be the same in the models subfolder of the addons (path and filename).

Adding image in java code in code name

I am new in code name one. I have to add image in a container(flow layout) with specific width and height.
1: codenameone's guide says that we have to add image in resource folder. Where is that resource folder?
2: To create image i am using createImage(path) of image class. if we put image file in resource folder then what is path of that image.
3: Is here any type restriction of image file in it.
Please help.
When you put the image you would like to add in your src folder the code should look as followed:
Label i = new Label();
Image img = Image.createImage("/imageToAdd.png");
i.setIcon(img);
You can change the label to whatever object you would like to use to display your image.
Resource file not folder, the ".res" file in the root of the SRC directory contains your theme as well as additional images you might need. The value here is that you can add multi-images (see tutorial) as well as write very portable code.
You can access the resource file in a GUI builder via fetchResourceFile() or in a non-GUI builder app using Resources.open (as is demonstrated in the init method).
You can also place arbitrary JPG/PNG files in the src root next to the res file. While there is no restriction from Codename One, devices tend to support PNG/JPG well and might fail with other formats.

ReportViewer WPF - Set Images Dynamically

I'd like to load image(s) at runtime (dynamically) into my report (inside the header).
I've already create the following parameter:
Name: Path
Datatype: String (should be the path to the image)
Allow Blank = True
Then I've draged and droped an image control to my report.
Set the name to: Image2
Imagesource: External
Use the following image: [#Path]
Now (back in my MainWindow) I've added the following code:
viewerInstance.LocalReport.EnableExternalImages = true;
List<ReportParameter> param1 = new List<ReportParameter>();
//header_2.png exists (for test purposes) in the root folder
param1.Add(new ReportParameter("Path", #"/header_2.png"));
viewerInstance.LocalReport.SetParameters(param1);
It doesn't work.
I'll get this error message:
The invocation of the constructor on type 'ReportViewer.MainWindow' that matches the specified binding constraints threw an exception.
{"The source of the report definition has not been specified"}
Any ideas?
I am not very sure about how to do it with External Images using the absolute path in SSRS 2008. But I guess I can provide with a workaround but this would work only in case you have all the images that you would be using in reports available to you beforehand.
You can add an Image control to the report. In the Image Control property, provide name, select the image source as Embedded, and click on Import, and select the image. Click Import. The image is imported. Now you can import all images like this. Once done, go to Image control property again and set the Use this Image as "[#Path]". Now you do not need to pass the absolute path but only the image name amongst the imported images which you can see under images in Report Data.
Also, if you want to use External Images, as per this msdn article you need to provide the Url for the image and not the absolute path. In this case you can hoist your image on a server and pass the path in the Path parameter. Select the image source as External. I have tested this and it works.
Edit: You can also upload the images to the ReportServer through the Report Manager and provide the path to that image as the relative path in the RDL after you specify the Image Source as external. e.g. /Report/Logo.png. You can also upload multiple images and use them by providing the path as parameter to the report.

how to override image in media library in WP7

I want to save image to media library in windows phone 7. I`m using this example http://msdn.microsoft.com/en-us/library/ff769549(v=VS.92).aspx . It works fine, the only problem that i have is that after image modification i call save procedure with the same file name, exactly like in example
MediaLibrary library = new MediaLibrary();
Picture pic = library.SavePicture("SavedPicture.jpg", myFileStream);
myFileStream.Close();
but modification is saved to another file, even thought i use the same file name when i call SavePicture (and i want to override the image file). What am i doing wrong?
Reading between the lines a little you are seeing a new picture appear in the phone saved pictures collection where you were expecting an existing one to be replaced?
You should note that the code you have referenced creates duplicate pictures. One is stored in the phones saved pictures collection and another is saved in isolated storage for the application.
Its not possible for an application to mutate an existing picture in the saved pictures collection even if that application is the original creator of the picture. When saved, a new picture is created in the saved pictures collection.
On the other hand the existing content of the file in the isolated storage is replaced with the new content.
You can't.
It's only possible to read and add images in/to the MediaLibrary.
It is not possible to edit or delete images.
This is by design.

looping through an image folder in a wpf application

I currently am loading all images in a folder in my "MyPictures" folder on my machine which works fine...
foreach (string filename in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)))
What I really want to be able to do, though, is load all the images in my Images folder within my solution project. Can someone please tell me the correct syntax to do this?
[Nothing in your question (as it is currently stated) is really directly related to WPF as opposed to C# (and Windows development) in general, as far as I can tell. You might get a better reply if the question was tagged to C# as opposed to just WPF.]
I don't think there is a way to reference your solution's folder as such (nor does it really make much sense, as the users of your application won't in general have the solution, only the distributables).
If you need the directory to be within your solution folder somehow, maybe you should refer to the directory your executable resides in (...\SolutionDir\bin\Debug), which you can get using
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly()
.GetModules()[0].FullyQualifiedName);
(Of course, you could tack \..\.. to that to refer to the SolutionDir instead, but that'd be a bit ugly.)
Depending on the usage of the images, though, it'd probably be better to put them under one of the defined special directories -- Environment.SpecialFolder.CommonApplicationData sounds like the best candidate, if the images are to be shared by all users.
One way to access images stored in a folder inside the WPF project is to do the following:
If you have already added the images inside an Images folder, Add the images file names in the Resources.resx file under Properties. You can access the images in the code by the following
string imageFilename = "pack://application:,,,/APP.UI;component/Images/" + Properties.Resources.imagefilename;
var src = new BitmapImage();
src.UriSource = new Uri(imageFilename , UriKind.Absolute);

Resources