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 / C++ / MFC
  4. GDI+ question: Bitmap:FromFile, how to detect non-existent image file?

GDI+ question: Bitmap:FromFile, how to detect non-existent image file?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestionwinformshelptutorial
3 Posts 3 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.
  • I Offline
    I Offline
    Indrawati
    wrote on last edited by
    #1

    Hi I am currently trying to use Bitmap::FromFile function provided by GDI+. It seems that the method does not provide any notification when the specified file does not exist. Subsequent calls to Bitmap::GetPixel also does not raise any error, it just gives a result of 255 for all the A, R,G, and B values. My question is, is there a way to check whether the FromFile method has successfully loaded an image or whether the image does not exist? Thanks!

    M J 2 Replies Last reply
    0
    • I Indrawati

      Hi I am currently trying to use Bitmap::FromFile function provided by GDI+. It seems that the method does not provide any notification when the specified file does not exist. Subsequent calls to Bitmap::GetPixel also does not raise any error, it just gives a result of 255 for all the A, R,G, and B values. My question is, is there a way to check whether the FromFile method has successfully loaded an image or whether the image does not exist? Thanks!

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      GDI+ is implemented strangely. The public interface is C++ classes, but to get around the fact that there's no common Application Binary Interface for C++ on Windows, and to allow both .NET and non-Microsoft compilers to use GDI+, the main body of the implementation is contained in a DLL with a 'flat', C-style interface. The implementation of the GDI+ classes is contained entirely within the GDI+ headers, in terms of this flat API. The Bitmap class is implemented in GdiPlusBitmap.h. Bitmap::FromFile simply creates a new Bitmap object, using the Bitmap(const WCHAR* filename, BOOL useEmbeddedColorManagement) constructor. If an error occurs, the underlying flat API call (GdipCreateBitmapFromFileICM or GdipCreateBitmapFromFile depending on whether the second parameter is set or not) returns an error code, which the Bitmap constructor stores internally. This error code can be retrieved using the GetLastStatus method (inherited from Image). I would expect that, if the file was not found, this method will return FileNotFound from the Status enumeration. Stability. What an interesting concept. -- Chris Maunder

      1 Reply Last reply
      0
      • I Indrawati

        Hi I am currently trying to use Bitmap::FromFile function provided by GDI+. It seems that the method does not provide any notification when the specified file does not exist. Subsequent calls to Bitmap::GetPixel also does not raise any error, it just gives a result of 255 for all the A, R,G, and B values. My question is, is there a way to check whether the FromFile method has successfully loaded an image or whether the image does not exist? Thanks!

        J Offline
        J Offline
        JonCage
        wrote on last edited by
        #3

        It's a bit dirty, but how about.. FILE* ofp = fopen("yourfile", "r"); if(ofp != NULL) { fclose(ofp); // File exists - go ahead and call Bitmap::FromFile } else { // File does NOT exist - warn the user } ..should work alright. Success is 99% failure

        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