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. Managed C++/CLI
  4. 32 Bitmaps -> 24 Dibs -> .bmp File

32 Bitmaps -> 24 Dibs -> .bmp File

Scheduled Pinned Locked Moved Managed C++/CLI
graphicsjsonperformancehelp
1 Posts 1 Posters 2 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.
  • S Offline
    S Offline
    Swinefeaster
    wrote on last edited by
    #1

    Grrr... I have done so much bitmap work that I feel embarassed even asking this! :) But I'm stuck! I create a ddb on a 32 bits per pixel display. Now I want to save this as a 24 bit bitmap --- rather than a 32 bit bitmap (which I can do just fine). I'm using the dib api functions provided by microsoft (slighty modified), namely this function: HDIB WINAPI CreateDibFromBitmap(HBITMAP hBitmap, HPALETTE hPal, int bitsPerPixel) { HDIB hDIB = NULL; BITMAP bm; // bitmap structure BITMAPINFOHEADER bi; // bitmap header BITMAPINFOHEADER FAR *lpbi = NULL; // pointer to BITMAPINFOHEADER DWORD dwLen = 0; // size of memory block HDIB h = NULL; // handle to DIB, temp handle HDC hDC = NULL; // handle to DC WORD biBits = 0; // bits per pixel /* check if bitmap handle is valid */ if (!hBitmap) return NULL; /* fill in BITMAP structure, return NULL if it didn't work */ if (!GetObject(hBitmap, sizeof(bm), (LPSTR)&bm)) return NULL; /* if no palette is specified, use default palette */ if (hPal == NULL) hPal = (HPALETTE)::GetStockObject(DEFAULT_PALETTE); if(bitsPerPixel == 0) { /* calculate bits per pixel */ biBits = bm.bmPlanes * bm.bmBitsPixel; } else { // Use specified bits per pixel. biBits = bitsPerPixel; } /* make sure bits per pixel is valid */ if (biBits <= 1) biBits = 1; else if (biBits <= 4) biBits = 4; else if (biBits <= 8) biBits = 8; else /* if greater than 8-bit, force to 24-bit */ biBits = 24; /* initialize BITMAPINFOHEADER */ bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bm.bmWidth; bi.biHeight = bm.bmHeight; bi.biPlanes = 1; bi.biBitCount = biBits; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; /* calculate size of memory block required to store BITMAPINFO */ dwLen = bi.biSize + PaletteSize((LPSTR)&bi); /* get a DC */ hDC = GetDC(NULL); /* select and realize our palette */ hPal = SelectPalette(hDC, hPal, FALSE); RealizePalette(hDC); /* alloc memory block to store our bitmap */ hDIB = (HDIB)GlobalAlloc(GHND, dwLen); /* if we couldn't get memory block */ if (!hDIB) { /* clean up and return NULL */ SelectPalett

    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