I need to load a picture to a pictureBox in a WindowsCE 6.0 . When I run the program in the mobile it tells me that it can't find the path.
This is my code:
this.pictureBox1.Image = new Bitmap(#" Data Source = \Program Files\Data\Image20120523_1.jpeg ");
I already tried with this paths to but it doesn't work:
path1: #"\Program Files\Data\Image20120523_1.jpeg"
path2: "\Program Files\Data\Image20120523_1.jpeg"
I have a database located in the same path and when I use it to make the connection it works ok, why it isn't working to load the image?
SOLUTION
This path works ok:
this.pictureBox1.Image = new Bitmap(#"\Program Files\Data\Image20120523_1.jpeg");
thanks for your help!
You need to use simple path to the image file here. Like this:
this.pictureBox1.Image = new Bitmap(#"E:\temp\photo\IMG_1461.JPG");
Related
This line of code works and retrieves the image from my bin\Debug\Images\ folder just fine.
panel1.BackgroundImage =
new Bitmap(Application.StartupPath + "\\Images\\Notavailable.png");
This line of code does not retrieve the image from my c: drive's Images folder.
panel1.BackgroundImage = new Bitmap("c:\\Images\\Notavailable.png");
Interesting things that might help:
The error I receive is "The given path's format is not supported." But, that same exact image loads from the first line I mentioned that is working.
I am running as an Administrator.
I really appreciate any help on this problem I can get and thank you all for your time.
I am using a custom cursor named hand2.cur in my C#-WPF application. I have added the cursor to a folder named Images which has all the images that I use in my application. However I've realized that I cannot add relative path to use my custom cursor as:
Cursor newCur = new Cursor("Images\\hand2.cur");
window.Cursor = newCur;
So I used this:
string absolute = System.IO.Path.GetFullPath("hand2.cur");
Cursor newCur = new Cursor(absolute);
window.Cursor = newCur;
This tries to find the hand2.cur file in the \bin\Release folder. So I added the file there and I got it working.
But the problem is, if I Publish this application and use it on a different computer, it does not work. Now the problem is with the cursor file path, because if I deploy it after commenting those 3 lines, it works correctly. So what do I do to rectify this problem?
I am using other images from the Image folder in my XAML code and they seem to port fine. But then again my knowledge of WPF is limited so if anyone has any ideas, that would help.
EDIT: I have added my Images folder to the project. I have also set the Build Action of the cursor file hand2.cur to Embedded Resource. However when I use the following two lines, I get an XAMLParseException.
System.Windows.Resources.StreamResourceInfo info = Application.GetResourceStream(new Uri("pack://application:,,,/Slideshow;component/Images/hand2.cur"));
window.Cursor = new System.Windows.Input.Cursor(info.Stream);
The Inner Exception field when I view the details of the error reads: {"Cannot locate resource 'images/hand2.cur'."}
You could make the cursor a resource in your app/assembly and then use GetResourceStream with the pack Uri to the resources location. Pass the Stream of the StreamResourceInfo to the ctor of the Cursor. e.g.
var info = Application.GetResourceStream(new Uri("pack://application:,,,/Images/hand2.cur"));
var cursor = new Cursor(info.Stream);
I've got this working after I added the cursor file hand2.cur to my Resource1.resx resource file. Then I used the following statement in my code:
window.Cursor = new Cursor(new System.IO.MemoryStream(MyNameSpace.Resource1.hand2));
I am developing a WPF application. I am letting user to select some picture and after that i want to save that image in EmployeePics directory which is in same Project directoy.
Here is the screenshot:
I have written following code but its not working:
string appPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EmployeePics\\");
File.Copy(Chosen_File, appPath + Chosen_File);
I am getting following exception:
Try to use File.Copy method. If it is not impossible, please, provide more details.
Update:
To resolve pictures directory you could use System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EmployeePics").
Update 2
Full code:
File.Copy(Chosen_File, Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EmployeePics"), Path.GetFileName(Chosen_File))).
I have a problem with displaying certain images in my application using C#. I am using the Image class to specify the location and the BitmapImage to specify the source. The UriSource is relative and I just specify the name. It worked for some images, but for others, the image simply does not appear. My image instance is 35x35 big and another is 100x100 big (pixels).
Anyone knows why this might be occurring and how to fix it?
Thanks.
Here's the code I used:
Image removeImage = new Image();
removeImage.HorizontalAlignment = HorizontalAlignment.Left;
removeImage.VerticalAlignment = VerticalAlignment.Top;
removeImage.Margin = new Thickness(490, 10, 0, 0);
removeImage.Width = 35;
removeImage.Height = 35;
BitmapImage source = new BitmapImage();
source.BeginInit();
source.UriSource = new Uri("delete.png", UriKind.RelativeOrAbsolute);
source.EndInit();
removeImage.Source = source;
removeImage.Stretch = Stretch.None;
removeImage.Visibility = Visibility.Visible;
removeImage.MouseDown += new MouseButtonEventHandler(removeImage_MouseDown);
Not sure about the location of image files. If images are in your current project folder then you have to set Copy To Output Directory=Copy Always property of image file from Properties Windows.
The best way that I know of to diagnose a problem like that (assuming a quick peer review of the code gets you nowhere), is to use ProcessMonitor: http://technet.microsoft.com/en-us/sysinternals/bb896645
You can use this tool to monitor all of the file activity on your machine (make sure to use the include/exclude filters to limit the noise).
It's very likely that the reason that the images are not showing up is because your application is looking for them in the wrong place (either they didn't get copied, or the relative path is off).
ProcessMonitor will log every attempt that Windows makes to access your .jpg (whether it fails or succeeds). If you search for your file name in the log, you should find it, probably along with an error message, and the full path that Windows was using to open the file.
The most common results I see are
Path that was actually being used was different from the path you needed.
The path was correct, but your files weren't there (build/copy/install problem)
The path was correct, but your web app did not have permissions to read the file.
In all those cases, ProcessMonitor will show you what happened.
I need use images in 2 .NET assemblies. One is WPF app {myApp.exe} and second is *.dll {myDll.dll}. File are located in this file structure:
**AppFolder** consist these files and one subfolder(avatars):
-myApp.exe
-myDll.dll
-avatars {folder} consist:
-manImages.jpg
-womanImages.jpg
I try user uri in this format
new Uri(#"C:\Users\avatars\manImages.jpg", UriKind.RelativeOrAbsolute);
but this format does not work, images are empty.
I would expect
new Uri(#"avatars\manImages.jpg", UriKind.RelativeOrAbsolute);
to work?
You could also try:
new Uri(Environment.CurrentDirectory + #"\avatars\manImages.jpg", UriKind.RelativeOrAbsolute);
On the dll side you can write this:
string imgPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "avatars\\manImages.jpg");