-
May 15th, 2008, 03:53 AM
#1
Gdiplus::Image:FromFile holds the file
I use GDI+ for displaying an image file.
1. Getting m_pImg = Gdiplus::Image::FromFile( m_fileName ); on browse button click
2. And drawing the image in OnDraw()
m_pGr->DrawImage( m_pImg, destX, destY, destWidth, destHeight);
( where m_pGr is Gdiplus :: Graphics )
When I checked I found that after calling FromFile the file is not release by the application untill I close the application.
So that when I tried CFile::Open( ) for the file, GetLasterror returned 32(The process cannot access the file because it is being used by another process. )
Could you please help me hoe can I get rid of this situation.
Is FromFile really holds the file? If so please suggest a good way to display the image.
-
May 15th, 2008, 05:11 AM
#2
Re: Gdiplus::Image:FromFile holds the file
Delete the image before CFile::Open( ): delete m_pImg
I love this forum. Thanks all for your help!
-
May 15th, 2008, 06:04 AM
#3
Re: Gdiplus::Image:FromFile holds the file
I tried the CFile::Open( ) from different application and the error occurs.
And if I delete the m_pImg object then InDraw will fail.
-
May 15th, 2008, 06:54 AM
#4
Re: Gdiplus::Image:FromFile holds the file
You draw the image in one application and call the CFile::Open() in a another?
I love this forum. Thanks all for your help!
-
May 15th, 2008, 07:19 AM
#5
Re: Gdiplus::Image:FromFile holds the file
Create image from file, make a copy of that image and delete the first image. You pass the cloned image to the OnDraw function.
Code:
// temporary image
Image *imgTemp = Gdiplus::Image::FromFile( m_fileName );
// the image you pass to OnDraw
Image img(imgTemp->GetWidth(), imgTemp->GetHeight());
// copy the image
Graphics g(&img);
g.DrawImage(imgTemp, 0, 0);
delete imgTemp ;
// Now you are safe to call CFile::Open()
Last edited by Chirieac; May 15th, 2008 at 07:22 AM.
I love this forum. Thanks all for your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|