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. gdi+ bitmap save on existing file - showing error

gdi+ bitmap save on existing file - showing error

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpwinforms
3 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.
  • G Offline
    G Offline
    Gopi Nath
    wrote on last edited by
    #1

    Hello, I am trying to draw an image (2nd image) over the other image (existing image file - 1st image) using gdi+ bitmap and graphics and then saving (overwriting) the same 1st image file. But saving is not getting done, when i use GetLasError(), it shows error message, "The process cannot access the file because it is being used by another process" Here is the code what i am doing.

    Gdiplus::Bitmap *gpBitmap = new Gdiplus::Bitmap(mImagePath1); /// existing image file
    Gdiplus::Graphics *gr = Gdiplus::Graphics::FromImage(gpBitmap);

    Gdiplus::Bitmap img(mImagePath2); // second image
    Gdiplus::Bitmap* pThumbnail = static_cast(img.GetThumbnailImage(32, 32, NULL, NULL));
    gr->DrawImage(pThumbnail, newWpos, newHpos); // drawing the second image on some position of first image

    Gdiplus::Status stat = gpBitmap->Save(mImagePath1, pClsid); // pClsid - image encoder set for png output

    I tried making copy also, but same issue. please suggest. Regards, Gopi.

    L 1 Reply Last reply
    0
    • G Gopi Nath

      Hello, I am trying to draw an image (2nd image) over the other image (existing image file - 1st image) using gdi+ bitmap and graphics and then saving (overwriting) the same 1st image file. But saving is not getting done, when i use GetLasError(), it shows error message, "The process cannot access the file because it is being used by another process" Here is the code what i am doing.

      Gdiplus::Bitmap *gpBitmap = new Gdiplus::Bitmap(mImagePath1); /// existing image file
      Gdiplus::Graphics *gr = Gdiplus::Graphics::FromImage(gpBitmap);

      Gdiplus::Bitmap img(mImagePath2); // second image
      Gdiplus::Bitmap* pThumbnail = static_cast(img.GetThumbnailImage(32, 32, NULL, NULL));
      gr->DrawImage(pThumbnail, newWpos, newHpos); // drawing the second image on some position of first image

      Gdiplus::Status stat = gpBitmap->Save(mImagePath1, pClsid); // pClsid - image encoder set for png output

      I tried making copy also, but same issue. please suggest. Regards, Gopi.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Your file mImagePath1 is still open to the Bitmap object. You should use a different path to save the new image.

      G 1 Reply Last reply
      0
      • L Lost User

        Your file mImagePath1 is still open to the Bitmap object. You should use a different path to save the new image.

        G Offline
        G Offline
        Gopi Nath
        wrote on last edited by
        #3

        Thank you Richard. This helps me to solve my issue. Regards, Gopi.

        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