![]() |
Multimedia »
General Graphics »
Bitmaps
Intermediate
License: The Code Project Open License (CPOL)
Simple class for drawing pictures (JPG, TIFF, GIF, etc...)By Peter HendrixThis article describes a class called CPicture that uses the IPicture class to draw pictures of almost any type to a CDC. |
VC6Win2K, Visual Studio, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
This article describes a very easy to use class that enables you to draw an image of almost any type to the screen.
Another feature it demonstrates is using the resource to store the images. By using the static function GetResource in another context, you can very easily store Wave-files or document templates in the resource of your application. This example has three images stored in memory: Image 1 is a JPEG image, image 2 is a GIF image and image 3 is a bitmap.
By examining the example, it will be very clear how the class should be used. Below, the most important code is shown.
This example also implements the CMemDC written by Keith Rule to enhance the drawing. (FlickerFree Drawing).
// The function 'LoadFromBuffer' prepares the IPicture class. // It requires a buffer filled with the contents of an image. bool CPicture::LoadFromBuffer(BYTE* pBuff, int nSize) { bool bResult = false; HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nSize); void* pData = GlobalLock(hGlobal); memcpy(pData, pBuff, nSize); GlobalUnlock(hGlobal); IStream* pStream = NULL; if (CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK) { HRESULT hr; if ((hr = OleLoadPicture(pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&m_pPicture)) == S_OK) bResult = true; pStream->Release(); } return bResult; } // This function draws the picture on the device context bool CPicture::Draw(CDC* pDC, int x, int y, int cx, int cy) { long hmWidth; long hmHeight; m_pPicture->get_Width(&hmWidth); m_pPicture->get_Height(&hmHeight); if (m_pPicture->Render(pDC->m_hDC, x, y, cx, cy, 0, hmHeight, hmWidth, -hmHeight, NULL) == S_OK) return true; return false; }
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 17 Jan 2001 Editor: Sean Ewington |
Copyright 2001 by Peter Hendrix Everything else Copyright © CodeProject, 1999-2009 Web17 | Advertise on the Code Project |