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. Pointers and SetDIBitsToDevice Question

Pointers and SetDIBitsToDevice Question

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionlearninggraphicshelp
2 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
    ursus zeta
    wrote on last edited by
    #1

    I am a novice to Visual C++ and windows programming, and so am attempting to acquire my understanding of it from Charles Petzold's: Programming Windows. No doubt many of you are familiar with it. I am becoming confused in using the SetDIBitsToDevice function that I am using to display bitmaps, that I have imported as a resource in the executable. And, so I have several questions about pointers, handles, and casting. In his book, Petzold describes supplying the necessary parameters, when calling the SetDIBitsToDevive function: "For the SetDIBitsToDevice and StretchDIBits functions, the information you need includes a pointer to the BITMAPINFO structure of the DIB. As you'll recall, the BITMAPINFO structure comprises the BITMAPINFOHEADER structure and the color table. So, this is simply a pointer to the packed DIB with appropriate casting." Do any of you understand what he is referring to when he says, 'appropriate casting'? Also, another question: I would like to display the bitmaps by using the FindResource and LoadImage function calls, which both return handles. Is there a way to use handles either as pointers, or by converting them safely to appropriate BITMAPINFO pointers and as pointers to the actual bitmap image bits? Is there a preferred casting operator that be used here? This is a description of how the author acquires the pointer to the image pixel bits: "The functions also require a pointer to the pixel bits. This is derivable from information in the information header, although the code is not pretty. Notice that this pointer can be calculated much more easily when you have access to the bfOffBits field of the BITMAPFILEHEADER structure. The bfOffBits field indicates the offset from the beginning of the DIB file to the pixel bits. You could simply add this offset to the BITMAPINFO pointer and then subtract the size of the BITMAPFILEHEADER structure. However, this doesn't help when you get a pointer to a packed DIB from the clipboard, because you don't have a BITMAPFILEHEADER structure." I imagine a n umber of you folks write programs for image processing, and have an intimate understanding of the mechanics involved here. I would appreciate any information. Thanks.

    D 1 Reply Last reply
    0
    • U ursus zeta

      I am a novice to Visual C++ and windows programming, and so am attempting to acquire my understanding of it from Charles Petzold's: Programming Windows. No doubt many of you are familiar with it. I am becoming confused in using the SetDIBitsToDevice function that I am using to display bitmaps, that I have imported as a resource in the executable. And, so I have several questions about pointers, handles, and casting. In his book, Petzold describes supplying the necessary parameters, when calling the SetDIBitsToDevive function: "For the SetDIBitsToDevice and StretchDIBits functions, the information you need includes a pointer to the BITMAPINFO structure of the DIB. As you'll recall, the BITMAPINFO structure comprises the BITMAPINFOHEADER structure and the color table. So, this is simply a pointer to the packed DIB with appropriate casting." Do any of you understand what he is referring to when he says, 'appropriate casting'? Also, another question: I would like to display the bitmaps by using the FindResource and LoadImage function calls, which both return handles. Is there a way to use handles either as pointers, or by converting them safely to appropriate BITMAPINFO pointers and as pointers to the actual bitmap image bits? Is there a preferred casting operator that be used here? This is a description of how the author acquires the pointer to the image pixel bits: "The functions also require a pointer to the pixel bits. This is derivable from information in the information header, although the code is not pretty. Notice that this pointer can be calculated much more easily when you have access to the bfOffBits field of the BITMAPFILEHEADER structure. The bfOffBits field indicates the offset from the beginning of the DIB file to the pixel bits. You could simply add this offset to the BITMAPINFO pointer and then subtract the size of the BITMAPFILEHEADER structure. However, this doesn't help when you get a pointer to a packed DIB from the clipboard, because you don't have a BITMAPFILEHEADER structure." I imagine a n umber of you folks write programs for image processing, and have an intimate understanding of the mechanics involved here. I would appreciate any information. Thanks.

      D Offline
      D Offline
      dan o
      wrote on last edited by
      #2

      hi, about casting see to the structure typedef struct tagBITMAPINFO { BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[1]; } BITMAPINFO; BITMAPINFO is almost same as BITMAPINFOHEADER casting means int iVar = 1; short sVar = (short)iVar; //I cast iVar to sVar int SetDIBitsToDevice( HDC hdc, // handle to device context int XDest, // x-coordinate of upper-left corner of // dest. rect. int YDest, // y-coordinate of upper-left corner of // dest. rect. DWORD dwWidth, // source rectangle width DWORD dwHeight, // source rectangle height int XSrc, // x-coordinate of lower-left corner of // source rect. int YSrc, // y-coordinate of lower-left corner of // source rect. UINT uStartScan, // first scan line in array UINT cScanLines, // number of scan lines CONST VOID *lpvBits, // address of array with DIB bits CONST BITMAPINFO *lpbmi, // address of structure with bitmap info. UINT fuColorUse // RGB or palette indexes ); .h CBitmap m_bmpLogo1; CString m_strLogoPath; HANDLE m_hBitmap; .cpp ::OnCreate() CFileFind filefind; CString strVal = strCurrentPath +"label.bmp"; m_strLogoPath = strVal; if (filefind.FindFile(strVal)) bLogo = TRUE; else m_strLogoPath = ""; if(bLogo) { if(!m_bmpLogo1.LoadBitmap(strVal)) { m_hBitmap = LoadImage (NULL,m_strLogoPath,IMAGE_BITMAP,0,0, LR_DEFAULTSIZE | LR_LOADFROMFILE ); //| LR_CREATEDIBSECTION if(!m_bmpLogo1.Attach(m_hBitmap)) m_strLogoPath = ""; } } //another function CBitmap bmp //class BITMAP Bitmap; //handle long cx=0,cy=0; CSize size bmp.Attach(m_hBitmap); bmp.GetBitmap(&Bitmap); size = bmp.GetBitmapDimension(); cx = size.cx; //or Bitmap.bmWidth cy = size.cy; //or Bitmap.bmHeight BITMAPINFO info; ZeroMemory( &info.bmiHeader, sizeof(BITMAPINFOHEADER) ); info.bmiHeader.biWidth = cx; // Set size you need info.bmiHeader.biHeight = cy; // Set size you need info.bmiHeader.biPlanes = 1; info.bmiHeader.biBitCount = 24; // Can be 8, 16, 32 bpp or other number info.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); //.. //I never used SetDIBitsToDevice() so i give you another example function //Let's create a new bitmap HDC dc= CreateCompatibleDC(NULL); VOID *pvBits; HBITMAP oldBmp

      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