gdi+ bitmap save on existing file - showing error
-
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 imageGdiplus::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.
-
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 imageGdiplus::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.
-
Your file mImagePath1 is still open to the Bitmap object. You should use a different path to save the new image.