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. How to save CBitmap to file

How to save CBitmap to file

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

    Hello, I need to make a *.bmp file out of my CBitmap file. I do not know about bitmaps so much and i cannot make conversions between different types. Can someone help me? Thanks in advance

    V J 2 Replies Last reply
    0
    • C caykahve

      Hello, I need to make a *.bmp file out of my CBitmap file. I do not know about bitmaps so much and i cannot make conversions between different types. Can someone help me? Thanks in advance

      V Offline
      V Offline
      vipinasda
      wrote on last edited by
      #2

      You can't save the CBitmap as it is into a file. You will have to convert the CBitmap which is a DDB into a DIB. The bytes for the pixels in the CBitmap are device dependent, only the graphics driver knows how to interpret the pixel values(RGB) corresponding to what a byte or triplet denote. So the first step would be to convert to a DIB. To do that, you will have to use the GetBitmap(...) method on the CBitmap and then get the DDB bitmap's dimensions. You should then create a DIB, this is normally done using CreateDIBSection(...), you should fill in the BITMAPINFOHEADER and then be done with creating the BMP with the right color depth. I would then BitBlt between a device context having a DDB into another memory device context having the DIB and the underlying graphics driver or DI would convert the DDB(your CBitmap)to DIB. You can now save the DIB to a file. Well the above are the fundamental set of operations to do it. There are already built-up classes here in codeproject. Have a look at this article "CDibData", linking to which you can get what you want. http://www.codeproject.com/bitmap/jscdibdata.asp[^] Microsoft - MVP

      1 Reply Last reply
      0
      • C caykahve

        Hello, I need to make a *.bmp file out of my CBitmap file. I do not know about bitmaps so much and i cannot make conversions between different types. Can someone help me? Thanks in advance

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        Articles at CP (Bitmaps & Palettes): CxImage, CDibData, "Saving a Drawing to a Bitmap File". There are probably others. INTP Every thing is relative...

        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