Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Out of Memory error for Iimage

Out of Memory error for Iimage

Scheduled Pinned Locked Moved C#
helpquestionxmlperformance
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tanuja123
    wrote on last edited by
    #1

    I want to display an image in my custom control.For that i used Image.FromFile(pathofimage)...But this statement gave an out of memory error. This happened when i changed an xml file to format 'bmp' and loaded that image.When i saw the file it had a red crossed symbol. How can i check whether an image file is a valid image file or not?..Please help....

    M S D 3 Replies Last reply
    0
    • T Tanuja123

      I want to display an image in my custom control.For that i used Image.FromFile(pathofimage)...But this statement gave an out of memory error. This happened when i changed an xml file to format 'bmp' and loaded that image.When i saw the file it had a red crossed symbol. How can i check whether an image file is a valid image file or not?..Please help....

      M Offline
      M Offline
      Manoj Kumar Rai
      wrote on last edited by
      #2

      Hi, The function "Image.FromFile" can through 2 types of Exceptions. 1)OutOfMemoryException 2)FileNotFoundException The first exception "OutOfMemoryException" will be thrown when the file does not have a valid image format. Hence, you put the above line in a try-catch block. There is problem with file format, when you get an exception type as OutOfMemoryException. Manoj

      1 Reply Last reply
      0
      • T Tanuja123

        I want to display an image in my custom control.For that i used Image.FromFile(pathofimage)...But this statement gave an out of memory error. This happened when i changed an xml file to format 'bmp' and loaded that image.When i saw the file it had a red crossed symbol. How can i check whether an image file is a valid image file or not?..Please help....

        S Offline
        S Offline
        Sandeep Akhare
        wrote on last edited by
        #3

        snoby wrote:

        when i changed an xml file to format 'bmp'

        Why did you change the format of file ?

        Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

        1 Reply Last reply
        0
        • T Tanuja123

          I want to display an image in my custom control.For that i used Image.FromFile(pathofimage)...But this statement gave an out of memory error. This happened when i changed an xml file to format 'bmp' and loaded that image.When i saw the file it had a red crossed symbol. How can i check whether an image file is a valid image file or not?..Please help....

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Explain how you "changed an XML file to format BMP"??

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          T 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Explain how you "changed an XML file to format BMP"??

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            T Offline
            T Offline
            Tanuja123
            wrote on last edited by
            #5

            While testing with my custom control...testers tried to rename an Xml file to Bmp file.In that extreme case , my custom control should not fail. So while fetching such a file my control failed.I can handle it in try -catch block.This i have already done.But is there any coding to restrict such exceptions from occuring ?

            D 1 Reply Last reply
            0
            • T Tanuja123

              While testing with my custom control...testers tried to rename an Xml file to Bmp file.In that extreme case , my custom control should not fail. So while fetching such a file my control failed.I can handle it in try -catch block.This i have already done.But is there any coding to restrict such exceptions from occuring ?

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              snoby wrote:

              testers tried to rename an Xml file to Bmp file.

              Of course that's not going to work...

              snoby wrote:

              In that extreme case , my custom control should not fail. So while fetching such a file my control failed.I can handle it in try -catch block.

              That's exactly what you have to do.

              snoby wrote:

              But is there any coding to restrict such exceptions from occuring ?

              You can't predict the future. You have no choice but to handle that exception. Even if the file is intentioned to be a valid image, files CAN be corrupted, no matter what you do. You simply don't have a choice here. You MUST handle the exception.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups