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. CImage -- Can't get it working

CImage -- Can't get it working

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionannouncement
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.
  • N Offline
    N Offline
    nde_plume
    wrote on last edited by
    #1

    I want to use CImage to save a dib as a jpg file. However, whenever I save it produces a black rectangle. Any suggestions? Here is my code: CImage img; int h = 292; int w = 248; // Create a dib section img.Create(w, h, 8); // Get a DC and draw in it (a red rectangle) HDC hdc = img.GetDC(); RECT r; r.top = r.left = 0; r.bottom = h; r.right = w; HBRUSH br = ::CreateSolidBrush(RGB(255,0,0)); ::FillRect(hdc, &r, br); // Release the DC img.ReleaseDC(); // now save the image img.Save("c:/temp/testimg.jpg", Gdiplus::ImageFormatJPEG); I get a black rectangle file with the correct dimensions. I am sure I am doing something dumb, but any help would be appreciated. TIA.

    C 1 Reply Last reply
    0
    • N nde_plume

      I want to use CImage to save a dib as a jpg file. However, whenever I save it produces a black rectangle. Any suggestions? Here is my code: CImage img; int h = 292; int w = 248; // Create a dib section img.Create(w, h, 8); // Get a DC and draw in it (a red rectangle) HDC hdc = img.GetDC(); RECT r; r.top = r.left = 0; r.bottom = h; r.right = w; HBRUSH br = ::CreateSolidBrush(RGB(255,0,0)); ::FillRect(hdc, &r, br); // Release the DC img.ReleaseDC(); // now save the image img.Save("c:/temp/testimg.jpg", Gdiplus::ImageFormatJPEG); I get a black rectangle file with the correct dimensions. I am sure I am doing something dumb, but any help would be appreciated. TIA.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If CImage is a GDI+ class ( I don't remember, but it looks like it, I thought it was just called Image ), then you need to select it into a Graphics object and draw on it there. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

      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