Eigene Bitmaps
- From: Johann Obermayr <Johann.Obermayr@xxxxxxxxxxx>
- Date: Wed, 29 Aug 2007 17:33:31 +0200
Hallo,
Ich muss einige Tausend Bitmaps im Speicher halten.
Dise sind nicht recht groß.
wenn ich sie in eine CBitmap laden, und dann in einem vector ablege,
vector<CBitmap *>, und wenn ich dann einige Zeichnen möchte, ist
ab einer gewissen anzahl nur noch ein schwarzer block zu sehen.
Ich vermute, das windows der gdi speicher aus geht.
Nun habe ich mir ein CMemoryBitmap erstellt.
class CMemoryBitmap
{
public:
CMemoryBitmap(void);
virtual ~CMemoryBitmap(void);
void Attach(CBitmap& bmp);
void Release();
DWORD GetBitmapMemorySize();
BITMAP& GetBitmap() { return m_bitMap; }
const BITMAP& GetBitmap() const { return m_bitMap; }
private:
BITMAP m_bitMap;
};
CMemoryBitmap::CMemoryBitmap(void)
{
memset(&m_bitMap, 0, sizeof(m_bitMap));
}
CMemoryBitmap::~CMemoryBitmap(void)
{
Release();
}
DWORD CMemoryBitmap::GetBitmapMemorySize()
{
DWORD dwSize(((((m_bitMap.bmWidth * m_bitMap.bmBitsPixel) + 31) & ~31) >> 3) * m_bitMap.bmHeight);
return dwSize;
}
void CMemoryBitmap::Release()
{
if (m_bitMap.bmBits)
delete [] m_bitMap.bmBits;
memset(&m_bitMap, 0, sizeof(m_bitMap));
}
void CMemoryBitmap::Attach(CBitmap& bmp)
{
bmp.GetBitmap(&m_bitMap);
DWORD dwMemorySize(GetBitmapMemorySize());
void *pData = new BYTE[dwMemorySize];
memcpy(pData, m_bitMap.bmBits, dwMemorySize);
m_bitMap.bmBits = pData;
}
und mit
BOOL DrawBitmap(CDC *pDC, CBitmap* pbm, int x, int y)
{
CDC mdc; // memory DC
BITMAP bm;
mdc.CreateCompatibleDC(pDC);
CBitmap* pOld = mdc.SelectObject(pbm);
pbm->GetObject(sizeof(bm), &bm);
pDC->MoveTo(x, y); pDC->LineTo(x + 200, y);
BOOL bRet = pDC->BitBlt( x, y, bm.bmWidth, bm.bmHeight, &mdc, 0, 0, SRCCOPY);
CString strText;
strText.Format("%u", bm.bmBitsPixel);
pDC->DrawText(strText, CRect(x + 100, y, x + 200, y + 20), DT_LEFT);
mdc.SelectObject(pOld);
return bRet;
}
BOOL DrawBitmap(CDC *pDC, CMemoryBitmap* pBitmap, int x, int y)
{
if (pBitmap)
{
CBitmap bmp;
bmp.CreateBitmapIndirect(&pBitmap->GetBitmap());
return DrawBitmap(pDC, &bmp, pt.x, pt.y);
}
return FALSE;
}
Zeiche ich die Bitmaps.
Aber nur Bitmaps mit bmBitsPixel == 1 werden dargestellt.
die anderen nicht.
Warum ?
Kann man das alles besser machen ?
Danke
Jimmy
.
- Follow-Ups:
- Re: Eigene Bitmaps
- From: Thorsten Albers
- Re: Eigene Bitmaps
- From: Martin Richter [MVP]
- Re: Eigene Bitmaps
- From: Karsten Schulz
- Re: Eigene Bitmaps
- Prev by Date: Re: ipcam
- Next by Date: Re: Get JPG
- Previous by thread: Get JPG
- Next by thread: Re: Eigene Bitmaps
- Index(es):
Relevant Pages
|