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. Help URGENT!!! Need to display an image whose path is decided at run time.

Help URGENT!!! Need to display an image whose path is decided at run time.

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
4 Posts 2 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
    awasthy
    wrote on last edited by
    #1

    Hi all, I am a new VC++ programmer. I need to acess a bmp file and read its pixels but urgently I need to know how to display an image on the screen whose path is chosen by browsing throgh the file system. Please Help Awasthy

    T 1 Reply Last reply
    0
    • A awasthy

      Hi all, I am a new VC++ programmer. I need to acess a bmp file and read its pixels but urgently I need to know how to display an image on the screen whose path is chosen by browsing throgh the file system. Please Help Awasthy

      T Offline
      T Offline
      Tareq Ahmed Siraj
      wrote on last edited by
      #2

      Use ::LoadImage() ... look it up in MSDN. Hope this helps. - tareq

      A 1 Reply Last reply
      0
      • T Tareq Ahmed Siraj

        Use ::LoadImage() ... look it up in MSDN. Hope this helps. - tareq

        A Offline
        A Offline
        awasthy
        wrote on last edited by
        #3

        Hi I have the path of the image and its handle using LoadImage() but how do I display it? No picture is being displayed. Awasthy Any work worth doing is worth doing well.

        T 1 Reply Last reply
        0
        • A awasthy

          Hi I have the path of the image and its handle using LoadImage() but how do I display it? No picture is being displayed. Awasthy Any work worth doing is worth doing well.

          T Offline
          T Offline
          Tareq Ahmed Siraj
          wrote on last edited by
          #4

          Assuming youre using MFC ... use the following code...

          HBITMAP bmp = (HBITMAP)::LoadImage(::GetModuleHandle(0), _T("Coffee.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
          CBitmap* pBitmap = CBitmap::FromHandle(bmp);
          CPaintDC dc(this);
          CDC memDc;
          memDc.CreateCompatibleDC(&dc);
          CBitmap* pMemBmp = memDc.SelectObject(pBitmap);
          dc.BitBlt(0,0,200,200,&memDc,0,0,SRCCOPY); //put your image width,height for the 3rd and 4th param
          
          memDc.SelectObject(pMemBmp);
          ::DeleteObject(bmp);
          

          - tareq

          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