Thread: C# Image Manipulation

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    62

    Question 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?

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    129
    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");
    He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

    The fool wonders, the wise man asks. - Benjamin Disraeli

    There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    62
    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)

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    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";
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-13-2010, 05:10 AM
  2. Image Manipulation
    By gadu in forum C++ Programming
    Replies: 0
    Last Post: 04-16-2009, 07:19 PM
  3. Image Manipulation
    By Jason84 in forum C++ Programming
    Replies: 1
    Last Post: 07-28-2004, 07:30 AM
  4. image manipulation
    By axon in forum C++ Programming
    Replies: 11
    Last Post: 05-01-2003, 12:22 PM
  5. Image manipulation
    By Colin in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2003, 12:46 PM

Tags for this Thread