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. displaying png's with GDI+

displaying png's with GDI+

Scheduled Pinned Locked Moved C / C++ / MFC
graphicswinformstutorial
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.
  • A Offline
    A Offline
    Adno
    wrote on last edited by
    #1

    hi im trying to get my head around GDI+ as far as i can tell i can only use it in the main function. With what i've done below the image shows up at first but when the window refreshes i.e (change the size of it) the image disappears is not repainted. main.. GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); { Graphics graphics(GetDC(hwnd)); Image* image = new Image(L"clock2alpha.png"); Bitmap bitmap(L"clock2alpha.png"); graphics.DrawImage(&bitmap, 0, 0); } GdiplusShutdown( gdiplusToken ); ..... im interested in displaying png images and how to access them outside the main method with GDI+ thank you

    J M 2 Replies Last reply
    0
    • A Adno

      hi im trying to get my head around GDI+ as far as i can tell i can only use it in the main function. With what i've done below the image shows up at first but when the window refreshes i.e (change the size of it) the image disappears is not repainted. main.. GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); { Graphics graphics(GetDC(hwnd)); Image* image = new Image(L"clock2alpha.png"); Bitmap bitmap(L"clock2alpha.png"); graphics.DrawImage(&bitmap, 0, 0); } GdiplusShutdown( gdiplusToken ); ..... im interested in displaying png images and how to access them outside the main method with GDI+ thank you

      J Offline
      J Offline
      Jun Du
      wrote on last edited by
      #2

      Because your code doesn't have a re-painting mechanism. The drawing code should be placed in a OnPaint() or OnDraw() handler, regardless of GDI or GDI+ rendering.

      Best, Jun

      1 Reply Last reply
      0
      • A Adno

        hi im trying to get my head around GDI+ as far as i can tell i can only use it in the main function. With what i've done below the image shows up at first but when the window refreshes i.e (change the size of it) the image disappears is not repainted. main.. GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); { Graphics graphics(GetDC(hwnd)); Image* image = new Image(L"clock2alpha.png"); Bitmap bitmap(L"clock2alpha.png"); graphics.DrawImage(&bitmap, 0, 0); } GdiplusShutdown( gdiplusToken ); ..... im interested in displaying png images and how to access them outside the main method with GDI+ thank you

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Lamefif wrote:

        as far as i can tell i can only use it in the main function.

        Where did you get that idea? :)

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        A 1 Reply Last reply
        0
        • M Mark Salsbery

          Lamefif wrote:

          as far as i can tell i can only use it in the main function.

          Where did you get that idea? :)

          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

          A Offline
          A Offline
          Adno
          wrote on last edited by
          #4

          hey Mark :) i dont know what i did earlier but it keept crashing at runtime, when i put the code above in a method it was weird. thank for your replies guys.

          M H 2 Replies Last reply
          0
          • A Adno

            hey Mark :) i dont know what i did earlier but it keept crashing at runtime, when i put the code above in a method it was weird. thank for your replies guys.

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Lamefif wrote:

            keept crashing at runtime, when i put the code above in a method

            hmm It was something else probably. You can make GDI+ calls anywhere (of course, all the usual thread safety issues apply if you're using multiple threads). If you're using GDI+ extensively, you can do the GdiplusStartup() just once - main/winmain is fine - and call GdiplusShutdown() just once after all drawing is done - just before returning from main/winmain is fine. If you have trouble in other functions you can always post related sample code here :) Mark

            "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

            1 Reply Last reply
            0
            • A Adno

              hey Mark :) i dont know what i did earlier but it keept crashing at runtime, when i put the code above in a method it was weird. thank for your replies guys.

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              Whats the error and where you used your code?


              WhiteSky


              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