Link to home
Start Free TrialLog in
Avatar of Epurchase
EpurchaseFlag for United States of America

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..

hBitmap = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), filename, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE|LR_DEFAULTCOLOR);
 
obj_bmp.Attach(hBitmap);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Epurchase

ASKER

Thanks much for your response..Sorry I didn't mention in my previous message that, it is not intended to store in a local file as the bmp image should be something very confidential and should be there in server itself..It will be displayed to the user by checking the given access..

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..

Hm, what avout deleting it afterwards?
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..
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..
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...
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..

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;
}

Open in new window

>>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")
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..