Epurchase
asked on
How to load BMP image from http URL?
HI,
I have scenario where loading bmp images using the code given. This code is working fine and the filename would be a local or unc file location. I want to load the bmp using the url location. for example in this case the file will be
http://server/test/abc.bmp.
I have tried this url as path and using that method it couldn't load the bmp. Can anybody help how to get the hBitmap object properly read from the url so that I can attach that as per the use given in the code..
Thanks In advance..
I have scenario where loading bmp images using the code given. This code is working fine and the filename would be a local or unc file location. I want to load the bmp using the url location. for example in this case the file will be
http://server/test/abc.bmp.
I have tried this url as path and using that method it couldn't load the bmp. Can anybody help how to get the hBitmap object properly read from the url so that I can attach that as per the use given in the code..
Thanks In advance..
hBitmap = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), filename, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE|LR_DEFAULTCOLOR);
obj_bmp.Attach(hBitmap);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hm, what avout deleting it afterwards?
ASKER
Yes. I agree..Deleting would be fine..But will it be more time consuming incase multiple files to read and attach ? Will it make the process slow?..
Please suggest..
Please suggest..
ASKER
I missed this concern in my previous message, while copy to client machine and deleting , then need to have access to that specific folder right..then each client need to keep the folder with all access right? or any other way..becoz sometime client restricts the access to delete anyfile from the drive..
Thanks..
Thanks..
Deleting the file will not have any noticeable impact on the performance. The main issue here is that there is simply no API to load a bitmap directly from an URL (keep in mind, these APIs were designed at the early 90s where there was no internet), so I'm afraid you'll have to go that route...
ASKER
oh..ok..What about opting URLOpenStream.. How to read the data after executing this method..I have debugged the program after executing the given code and found that onDataAvailable, its getting the data from url ..but how to read that data to HBITMAP..
will this way work, if we can read that data..what do you suggest for this option..
Thanks very much for all your quick responses..
will this way work, if we can read that data..what do you suggest for this option..
Thanks very much for all your quick responses..
CBSCallbackImpl callback;
HRESULT hResult = ::URLOpenStream(NULL,bmpFile,0,&callback);
STDMETHODIMP CBSCallbackImpl::OnDataAvailable(DWORD, DWORD dwSize,
FORMATETC *, STGMEDIUM *stgmed )
{
TRACE(_T("IBindStatusCallback::OnDataAvailable %ld\n"), dwSize );
if ( stgmed ) {
if ( stgmed->pstm ) {
ULONG bytesRead = 0;
BYTE *data = new BYTE[ dwSize ];
HRESULT hRes = stgmed->pstm->Read( data, dwSize, &bytesRead );
delete[] data;
return hRes;
}
}
return S_OK;
}
>>oh..ok..What about opting URLOpenStream..
That does pretty much the same - with the only diofference being that you could store that data in memory instead of on disk. So, if yo udon't
delete[] data;
youÄll have th ebitmap data in there. Unfortunately, in a base64 encoded format which you can decode to a binary bitmap using http://www.codeproject.com/KB/cpp/base64coding.aspx ("Base64 Encoding And Decoding")
That does pretty much the same - with the only diofference being that you could store that data in memory instead of on disk. So, if yo udon't
delete[] data;
youÄll have th ebitmap data in there. Unfortunately, in a base64 encoded format which you can decode to a binary bitmap using http://www.codeproject.com/KB/cpp/base64coding.aspx ("Base64 Encoding And Decoding")
ASKER
Hi jkr,
As you said that that the perfomance would be same for both, I am preferring the way you have suggested..
Hence it will save in to one file and then delete from there..
Really appreaciating your help and thanks much..
As you said that that the perfomance would be same for both, I am preferring the way you have suggested..
Hence it will save in to one file and then delete from there..
Really appreaciating your help and thanks much..
ASKER
I have seen in one article the use of "URLOpenStream" and tried that..It is found that the onDataAvailable for the callback reference is able to dowload the bmp data to bytes buffer..but the return type of the onDataAvailable method is HRESULT and coule return "S_OK"..Can you please help me if it this way can work for my requirement then, how to read the downloaded data and get it into the HBITMAP object..
Appreciating your help and thanks..