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. Creating 16 color bitmap from DC

Creating 16 color bitmap from DC

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsjsonperformancequestion
1 Posts 1 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.
  • V Offline
    V Offline
    Vinaya
    wrote on last edited by
    #1

    Hi, I need to modify a 16 color bmp and then save it as a seperate file. I loaded a 16 color 48x48 bmp file on DC using the LoadImage() and BitBlt() API. Using GDI functions, I change the display on the DC, say draw a line on the DC, on top of the image displayed. Now I need to capture the current DC ( bmp image + the changes,i.e., the line) and create a new BMP file. For 256 color and 16 color BMP file, the new BMP created is a plain white imgage, if I load the image with 'LR_CREATEDIBSECTION' flag in LoadImage API. else I get am able to create the file, but the image size is different. For the 24 bpp the application is working fine. Where am i doing wrong. I am using the 'CreateCompatibleBitmap()' to create the bitmap from DC. Is there any other way?. HBITMAP hBMP; RECT r; GetClientRect(GetDlgItem(hWnd,IDC_STATIC_1),&r); HDC memDC = CreateCompatibleDC ( pDC ); hBMP = (HBITMAP)LoadImage(hResDll ,filename,IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); SelectObject ( memDC, hBMP ); BitBlt(pDC,r.left ,r.top ,imgWidth,imgHeight ,memDC,0,0,SRCCOPY); DeleteObject(hBMP); .............................. To capture the modified BMP from DC ............................. RECT rc; GetClientRect(GetDlgItem(hWndDlg,IDC_STATIC_1),&rc); HDC hScreenDC = GetWindowDC(GetDlgItem(hWndDlg,IDC_STATIC_1)); HDC hmemDC = CreateCompatibleDC(hScreenDC); int ScreenWidth = rc.right; int ScreenHeight = rc.bottom; HBITMAP hmemBM = CreateCompatibleBitmap(hScreenDC, ScreenWidth ,ScreenHeight ); SelectObject(hmemDC, hmemBM); bufLen= filesize; HGLOBAL hpxldata = GlobalAlloc(GMEM_FIXED ,imgWidth * imgHeight * 3 ); void * lpvpxldata = GlobalLock(hpxldata); // fill .bmp - structures BITMAPINFO bmInfo; bmInfo.bmiHeader.biSize = 40; bmInfo.bmiHeader.biWidth = imgWidth; bmInfo.bmiHeader.biHeight = imgHeight; bmInfo.bmiHeader.biPlanes = 1; bmInfo.bmiHeader.biBitCount = 24; bmInfo.bmiHeader.biCompression = 0; bmInfo.bmiHeader.biSizeImage = 0; bmInfo.bmiHeader.biXPelsPerMeter = 0; bmInfo.bmiHeader.biYPelsPerMeter = 0; bmInfo.bmiHeader.biClrUsed = 0; bmInfo.bmiHeader.biClrImportant = 0; BITMAPFILEHEADER bmFileHeader; bmFileHeader.bfType = 19778; bmFileHeader.bfSize = filesize; bmFileHeader.bfReserved1 = 0; bmFileHeader.bfReserved2 = 0; bmFileHeader.bfOffBits = 54; // copy bitmap data into global memory StretchBlt(hmemDC,0 ,0 ,imgWidth ,imgHeight,hScreenDC,0,0,ScreenWidth,ScreenHeight ,SRCCOPY); int nret = GetDIBits(hmemDC, hmemBM, 0, im

    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