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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SetDIBitsToDevice causes image to flip, why?

SetDIBitsToDevice causes image to flip, why?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestion
3 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.
  • U Offline
    U Offline
    uus99
    wrote on last edited by
    #1

    I have a grayscale image of 100x100px, where the top half is gray (pixel value=128) and the bottom half is black (value=0); however when i plot it to screen, it comes flipped. Why is that? Can anyone help? Here is the source; The result on screen is black followed by gray, which is not what i want. Why is it flipped? void CPopUpDlg::OnButton1() { BITMAPINFO *m_pBmiImage; CDC *pDC; BYTE *m_pImg; pDC =this->GetDC(); DWORD bitmapInfoSize; int i; int Width=100; int Height=100; //image of 8bit , 100x100pixels int m_iSize = Width * Height; m_pImg = new BYTE[m_iSize]; // Bitmap info structure for the image bitmapInfoSize = sizeof(BITMAPINFO) + 255*sizeof(RGBQUAD); m_pBmiImage = (BITMAPINFO*)new BYTE[bitmapInfoSize]; m_pBmiImage->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); m_pBmiImage->bmiHeader.biPlanes = 1; m_pBmiImage->bmiHeader.biBitCount = 8; m_pBmiImage->bmiHeader.biCompression = BI_RGB; m_pBmiImage->bmiHeader.biSizeImage = 0; m_pBmiImage->bmiHeader.biXPelsPerMeter = 0; m_pBmiImage->bmiHeader.biYPelsPerMeter = 0; m_pBmiImage->bmiHeader.biClrUsed = 0; m_pBmiImage->bmiHeader.biClrImportant = 0; m_pBmiImage->bmiHeader.biWidth = Width; m_pBmiImage->bmiHeader.biHeight = Height; //Set the color table as just grays. for (i = 0 ; i < 256 ; i++) { m_pBmiImage->bmiColors[i].rgbBlue = (BYTE)i; m_pBmiImage->bmiColors[i].rgbGreen = (BYTE)i; m_pBmiImage->bmiColors[i].rgbRed = (BYTE)i; m_pBmiImage->bmiColors[i].rgbReserved = 0; } //first half of the image is gray for(i=0;i<100*50;i++) m_pImg[i]=128; //second half of the image is black for(i=100*50;i<100*100;i++) m_pImg[i]=0; //Plot to screen SetDIBitsToDevice(pDC->m_hDC, 100, 100, Width, Height, 0, 0, 0, Height, m_pImg, m_pBmiImage, DIB_RGB_COLORS); delete[] m_pImg; delete m_pBmiImage; }

    M 1 Reply Last reply
    0
    • U uus99

      I have a grayscale image of 100x100px, where the top half is gray (pixel value=128) and the bottom half is black (value=0); however when i plot it to screen, it comes flipped. Why is that? Can anyone help? Here is the source; The result on screen is black followed by gray, which is not what i want. Why is it flipped? void CPopUpDlg::OnButton1() { BITMAPINFO *m_pBmiImage; CDC *pDC; BYTE *m_pImg; pDC =this->GetDC(); DWORD bitmapInfoSize; int i; int Width=100; int Height=100; //image of 8bit , 100x100pixels int m_iSize = Width * Height; m_pImg = new BYTE[m_iSize]; // Bitmap info structure for the image bitmapInfoSize = sizeof(BITMAPINFO) + 255*sizeof(RGBQUAD); m_pBmiImage = (BITMAPINFO*)new BYTE[bitmapInfoSize]; m_pBmiImage->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); m_pBmiImage->bmiHeader.biPlanes = 1; m_pBmiImage->bmiHeader.biBitCount = 8; m_pBmiImage->bmiHeader.biCompression = BI_RGB; m_pBmiImage->bmiHeader.biSizeImage = 0; m_pBmiImage->bmiHeader.biXPelsPerMeter = 0; m_pBmiImage->bmiHeader.biYPelsPerMeter = 0; m_pBmiImage->bmiHeader.biClrUsed = 0; m_pBmiImage->bmiHeader.biClrImportant = 0; m_pBmiImage->bmiHeader.biWidth = Width; m_pBmiImage->bmiHeader.biHeight = Height; //Set the color table as just grays. for (i = 0 ; i < 256 ; i++) { m_pBmiImage->bmiColors[i].rgbBlue = (BYTE)i; m_pBmiImage->bmiColors[i].rgbGreen = (BYTE)i; m_pBmiImage->bmiColors[i].rgbRed = (BYTE)i; m_pBmiImage->bmiColors[i].rgbReserved = 0; } //first half of the image is gray for(i=0;i<100*50;i++) m_pImg[i]=128; //second half of the image is black for(i=100*50;i<100*100;i++) m_pImg[i]=0; //Plot to screen SetDIBitsToDevice(pDC->m_hDC, 100, 100, Width, Height, 0, 0, 0, Height, m_pImg, m_pBmiImage, DIB_RGB_COLORS); delete[] m_pImg; delete m_pBmiImage; }

      M Offline
      M Offline
      Monty2
      wrote on last edited by
      #2

      its a complete guess, might not work but worth a try m_pBmiImage->bmiHeader.biHeight = -Height; specify negative height i can't even remember what my point is now, but anyway, i'm correct Barring unforeseen acts of God and Adminstrators, my server will be up tomorrow. I'm more worried about the Adminstrators.

      U 1 Reply Last reply
      0
      • M Monty2

        its a complete guess, might not work but worth a try m_pBmiImage->bmiHeader.biHeight = -Height; specify negative height i can't even remember what my point is now, but anyway, i'm correct Barring unforeseen acts of God and Adminstrators, my server will be up tomorrow. I'm more worried about the Adminstrators.

        U Offline
        U Offline
        uus99
        wrote on last edited by
        #3

        Thanks, works just fine! Now the image plots correctly! Thanks a lot for the prompt reply!! :)

        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