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. Displays the image in Picture Control.

Displays the image in Picture Control.

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
13 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.
  • U User 12627902

    I just started to study this theme, so strongly do not swear. Tell me why this code works.

    HBITMAP startBitmap = (HBITMAP)LoadImage(NULL, "D:\\159.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    m_PictureControl.SetBitmap(startBitmap);

    And this does not work.

    HANDLE FileR = CreateFile("D:\\159.bmp", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    DWORD size_file = GetFileSize(FileR, 0);
    HBITMAP startBitmap = (HBITMAP)malloc(size_file);
    DWORD dwReadW;
    ReadFile(FileR, startBitmap, size_file, &dwReadW, NULL);
    m_PictureControl.SetBitmap(startBitmap);

    As I assume the buffer is necessary as it is to prepare before an image displayed on the screen. But unfortunately I do not understand how to do it.

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #4

    Member 12661464 wrote:

    And this does not work.

    Which means what exactly? Have you stepped through the code to make sure that CreateFile(), GetFileSize(), ReadFile(), and SetBitmap() all return "success" values?

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

    1 Reply Last reply
    0
    • U User 12627902

      I just started to study this theme, so strongly do not swear. Tell me why this code works.

      HBITMAP startBitmap = (HBITMAP)LoadImage(NULL, "D:\\159.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
      m_PictureControl.SetBitmap(startBitmap);

      And this does not work.

      HANDLE FileR = CreateFile("D:\\159.bmp", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
      DWORD size_file = GetFileSize(FileR, 0);
      HBITMAP startBitmap = (HBITMAP)malloc(size_file);
      DWORD dwReadW;
      ReadFile(FileR, startBitmap, size_file, &dwReadW, NULL);
      m_PictureControl.SetBitmap(startBitmap);

      As I assume the buffer is necessary as it is to prepare before an image displayed on the screen. But unfortunately I do not understand how to do it.

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #5

      The first reads file and "convert" the read data to be interpreted as a HBITMAP. The second just reads some binary data that cannot be interpreted as a HBITMAP.:suss:

      U 1 Reply Last reply
      0
      • V Victor Nijegorodov

        The first reads file and "convert" the read data to be interpreted as a HBITMAP. The second just reads some binary data that cannot be interpreted as a HBITMAP.:suss:

        U Offline
        U Offline
        User 12627902
        wrote on last edited by
        #6

        Victor Nijegorodov wrote:

        cannot be interpreted as a HBITMAP

        I understand this, but I can't understand how do I convert this data to an image, how do I process the buffer?

        V 1 Reply Last reply
        0
        • U User 12627902

          Victor Nijegorodov wrote:

          cannot be interpreted as a HBITMAP

          I understand this, but I can't understand how do I convert this data to an image, how do I process the buffer?

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #7

          Well, what is your goal? Are you trying to reinvent the wheel? Or what?:confused:

          U 1 Reply Last reply
          0
          • V Victor Nijegorodov

            Well, what is your goal? Are you trying to reinvent the wheel? Or what?:confused:

            U Offline
            U Offline
            User 12627902
            wrote on last edited by
            #8

            I want to understand what the LoadImage function does with a file, cuts off the header ? How does it convert data? I find the image in the resources of the file, it does not lie in the open as a picture. I read in buffer specifically the place where image of the is.

            V 1 Reply Last reply
            0
            • U User 12627902

              I want to understand what the LoadImage function does with a file, cuts off the header ? How does it convert data? I find the image in the resources of the file, it does not lie in the open as a picture. I read in buffer specifically the place where image of the is.

              V Offline
              V Offline
              Victor Nijegorodov
              wrote on last edited by
              #9

              Have a look at [Storing an Image - Windows applications | Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/gdi/storing-an-image) and other info [About Bitmaps - Windows applications | Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/gdi/about-bitmaps)

              1 Reply Last reply
              0
              • U User 12627902

                I just started to study this theme, so strongly do not swear. Tell me why this code works.

                HBITMAP startBitmap = (HBITMAP)LoadImage(NULL, "D:\\159.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
                m_PictureControl.SetBitmap(startBitmap);

                And this does not work.

                HANDLE FileR = CreateFile("D:\\159.bmp", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
                DWORD size_file = GetFileSize(FileR, 0);
                HBITMAP startBitmap = (HBITMAP)malloc(size_file);
                DWORD dwReadW;
                ReadFile(FileR, startBitmap, size_file, &dwReadW, NULL);
                m_PictureControl.SetBitmap(startBitmap);

                As I assume the buffer is necessary as it is to prepare before an image displayed on the screen. But unfortunately I do not understand how to do it.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #10

                The data you have read from the file is in raw format and needs to be converted to Bitmap format. Your code is missing the conversion part. See bitmap format - Google Search[^].

                U 1 Reply Last reply
                0
                • L Lost User

                  The data you have read from the file is in raw format and needs to be converted to Bitmap format. Your code is missing the conversion part. See bitmap format - Google Search[^].

                  U Offline
                  U Offline
                  User 12627902
                  wrote on last edited by
                  #11

                  I would be very grateful for a hint which WinAPI functions convert data to Bitmap format.

                  L 1 Reply Last reply
                  0
                  • U User 12627902

                    I would be very grateful for a hint which WinAPI functions convert data to Bitmap format.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #12

                    Start at BITMAP (wingdi.h) | Microsoft Docs[^]. And read on from there on the other links.

                    1 Reply Last reply
                    0
                    • U User 12627902

                      I just started to study this theme, so strongly do not swear. Tell me why this code works.

                      HBITMAP startBitmap = (HBITMAP)LoadImage(NULL, "D:\\159.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
                      m_PictureControl.SetBitmap(startBitmap);

                      And this does not work.

                      HANDLE FileR = CreateFile("D:\\159.bmp", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
                      DWORD size_file = GetFileSize(FileR, 0);
                      HBITMAP startBitmap = (HBITMAP)malloc(size_file);
                      DWORD dwReadW;
                      ReadFile(FileR, startBitmap, size_file, &dwReadW, NULL);
                      m_PictureControl.SetBitmap(startBitmap);

                      As I assume the buffer is necessary as it is to prepare before an image displayed on the screen. But unfortunately I do not understand how to do it.

                      U Offline
                      U Offline
                      User 12627902
                      wrote on last edited by
                      #13

                      Now that I have understood everything and got the right result, I read my question with a smile. Thank you very much to everyone who sent me in the right direction.

                      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