-
C# Image Manipulation
Hello all!
I'll be short with my question.
I have an absolute path to a .png image.
I want to pre-load it as a Bitmap object.
This gives an error:
Code:
Bitmap loaded = new Bitmap(@absolute_path_string);
Saying that the parameter is not valid (no other details have been given)
Now I read something from the .NET resource about PngBitmapDecoder
but I cannot find the System.Windows.Media.Imaging reference & namespace.
So I'm wondering, what would be the correct way of doing this?
-
It should work correctly with PNG. Have you tried changing the .NET compiling version? I believe the earlier ones may not have supported PNG as a file type.
The path should also be (just to make sure):
Code:
Bitmap myBitmap = new Bitmap(@"C:\Test.PNG");
-
I'm using .NET version 4.*
and yes the absolute path looks like so:
"C:\\*long path string*\\something.png"
It doesn't work for some reason though (as I have written: invalid parameter)
-
Your first example of the absolute path was, I think, wrong. You don't use @ with a variable, you use it with a string so that it escapes it for you. For example, in your last post you have \\ in there. With @ you don't have to. Do this:
@"c:\long string path\something.png"
Instead of:
@"c:\\long string path\\something.png"
Because if you use @, it will make it exactly like what you have, properly escaped: two quotes in a row, not just one, and try to read that as the path.
Quzah.
-
quzah nailed it. To complement on his answer:
Either use the full path constant as illustrated on his post, or if you require the variable to be passed to the Bitmap constructor, declare it as:
Code:
string absolute_path_string = @"c:\long string path\something.png";