Click here to Skip to main content
15,897,891 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: image to stream Pin
Iain Clarke, Warrior Programmer26-Feb-08 1:51
Iain Clarke, Warrior Programmer26-Feb-08 1:51 
GeneralRe: image to stream Pin
Paulraj G26-Feb-08 1:53
Paulraj G26-Feb-08 1:53 
GeneralAbout graphics memory Pin
manish.patel26-Feb-08 1:31
manish.patel26-Feb-08 1:31 
GeneralRe: About graphics memory Pin
Mark Salsbery26-Feb-08 5:35
Mark Salsbery26-Feb-08 5:35 
Generalmemorystream Pin
Paulraj G26-Feb-08 0:40
Paulraj G26-Feb-08 0:40 
GeneralRe: memorystream Pin
Iain Clarke, Warrior Programmer26-Feb-08 0:54
Iain Clarke, Warrior Programmer26-Feb-08 0:54 
GeneralRe: memorystream Pin
Paulraj G26-Feb-08 1:20
Paulraj G26-Feb-08 1:20 
GeneralRe: memorystream Pin
Iain Clarke, Warrior Programmer26-Feb-08 1:38
Iain Clarke, Warrior Programmer26-Feb-08 1:38 
I had the same problem as you... (I think). I needed to use OleLoadPicture, and that loaded from a stream.

It was jigsaw game app, and I wanted to be able to load jpgs, bmps, gifs, tifs, pngs, etc.

Looking at my code now, I'm a little unsure of casting the result from CoTaskMemAlloc to an HGLOBAL, but it seemed to work fine!

Anyway, take what you can, and avoid any bad habits.

Iain.


HBITMAP CJigSawDoc::JigLoadPicture (CFile *f, CSize szImage)
{
	IPicture *iPic = NULL;

	DWORD dwFileSize, dwRead;
	dwFileSize = f->GetLength ();
	void *pBuffer = ::CoTaskMemAlloc (dwFileSize);
	if (NULL == pBuffer)
		return NULL;

	dwRead = f->Read (pBuffer, dwFileSize);
	if (dwRead != dwFileSize)
		return NULL;

	IStream *iStream = NULL;
	if (FAILED(::CreateStreamOnHGlobal ((HGLOBAL)pBuffer, FALSE, &iStream)))
		return NULL;

	::OleLoadPicture(iStream, 0, FALSE, IID_IPicture, (LPVOID*)&iPic);
	iStream->Release ();
	::CoTaskMemFree (pBuffer);

	if (iPic == NULL)
		return NULL;

        CWindowDC dc (CWnd::FromHandle (::GetDesktopWindow ()));

	HBITMAP	hBitmap = NULL, hOldBitmap = NULL;
	HDC		hMemDC = CreateCompatibleDC (dc);

	CSize	pxSz, hmSz, szScreen (::GetSystemMetrics (SM_CXFULLSCREEN), ::GetSystemMetrics (SM_CYFULLSCREEN));
	iPic->get_Width (&hmSz.cx);
	iPic->get_Height(&hmSz.cy);
	AtlHiMetricToPixel(&hmSz, &pxSz);

	szScreen.cx = (int)Interpolate (0, szScreen.cx, 0.9, 1.0);
	szScreen.cy = (int)Interpolate (0, szScreen.cy, 0.9, 1.0);
	if (pxSz.cx > szScreen.cx)
	{
		pxSz.cy = (int)Interpolate (0, pxSz.cy, szScreen.cx, pxSz.cx);
		pxSz.cx = szScreen.cx;
	}
	if (pxSz.cy > szScreen.cy)
	{
		pxSz.cx = (int)Interpolate (0, pxSz.cx, szScreen.cy, pxSz.cy);
		pxSz.cy = szScreen.cy;
	}
	
	hBitmap = ::CreateCompatibleBitmap (dc, pxSz.cx, pxSz.cy);
	hOldBitmap = (HBITMAP) SelectObject (hMemDC, hBitmap);

	// Render upside-upside down
	iPic->Render (hMemDC, 0,pxSz.cy - 1, pxSz.cx, -pxSz.cy, 0,0, hmSz.cx, hmSz.cy, NULL);
	iPic->Release ();
	iPic = NULL;

	SelectObject (hMemDC, hOldBitmap);

	return hBitmap;
}


Iain Clarke appearing in spite of being begged not to by CPallini.

GeneralRe: memorystream Pin
Rajkumar R26-Feb-08 1:41
Rajkumar R26-Feb-08 1:41 
GeneralRe: memorystream Pin
Paulraj G26-Feb-08 1:56
Paulraj G26-Feb-08 1:56 
GeneralRe: memorystream Pin
Rajkumar R26-Feb-08 2:05
Rajkumar R26-Feb-08 2:05 
GeneralRe: memorystream Pin
Mark Salsbery26-Feb-08 5:48
Mark Salsbery26-Feb-08 5:48 
QuestionRe: memorystream Pin
David Crow26-Feb-08 3:19
David Crow26-Feb-08 3:19 
GeneralRe: memorystream Pin
CPallini26-Feb-08 4:28
mveCPallini26-Feb-08 4:28 
Generalregarding project!! Pin
rowdy_vc++26-Feb-08 0:37
rowdy_vc++26-Feb-08 0:37 
GeneralRe: regarding project!! Pin
Rajesh R Subramanian26-Feb-08 0:45
professionalRajesh R Subramanian26-Feb-08 0:45 
AnswerRe: regarding project!! Pin
Rajkumar R26-Feb-08 0:45
Rajkumar R26-Feb-08 0:45 
GeneralRe: regarding project!! Pin
rowdy_vc++26-Feb-08 1:03
rowdy_vc++26-Feb-08 1:03 
GeneralRe: regarding project!! Pin
Rajkumar R26-Feb-08 1:10
Rajkumar R26-Feb-08 1:10 
GeneralRe: regarding project!! Pin
Maxwell Chen26-Feb-08 4:10
Maxwell Chen26-Feb-08 4:10 
QuestionRe: regarding project!! Pin
Rajkumar R26-Feb-08 5:07
Rajkumar R26-Feb-08 5:07 
GeneralRe: regarding project!! Pin
Maxwell Chen26-Feb-08 6:36
Maxwell Chen26-Feb-08 6:36 
GeneralRe: regarding project!! Pin
Maxwell Chen26-Feb-08 1:00
Maxwell Chen26-Feb-08 1:00 
GeneralRe: regarding project!! Pin
rowdy_vc++26-Feb-08 1:14
rowdy_vc++26-Feb-08 1:14 
GeneralDLL found with VS2003 but not VS2005 Pin
Merlin Tintin26-Feb-08 0:10
Merlin Tintin26-Feb-08 0:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.