<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CBitmap]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe (mal wieder) ein Problem mit Bitmaps:</p>
<pre><code class="language-cpp">CDC     memDC; 
CDC*    pDC = GetDC(); 
CBitmap *pOldBitmap;   

memDC.CreateCompatibleDC(pDC);
(*Bitmap).CreateCompatibleBitmap(pDC, width, height); 
pOldBitmap = memDC.SelectObject(Bitmap); 

const int nXMIN = -100;
const int nXMAX = 100;
const int nYMIN = -100;
const int nYMAX = 100;

// Map-Mode auf LOENGLISH setzen
memDC.SetMapMode(MM_LOENGLISH);

// Neuer Nullpunkt
CPoint     CZero(-nXMIN,nYMIN);
// Verschiebung des Nullpunktes aufgrund Mapping-Mode ausrechnen
memDC.LPtoDP(&amp;CZero);
memDC.SetViewportOrg(CZero);

// Routine für's zeichnen	

memDC.SelectObject(pOldBitmap);
ReleaseDC(&amp;memDC);
</code></pre>
<p>Der Code ist soweit in Ordnung, aber der Hintergrund ist schwarz.</p>
<p>Mit</p>
<pre><code>memDC.FillSolidRect(0, 0, width, height, RGB(255,255,255)); // weisser Hintergrund
</code></pre>
<p>bekomme ich nun einen weissen Hintergrund .. und die Anwendung läuft. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p>Jetzt ist es so, dass die Bitmap ziemlich groß ist. 32467 x 480.<br />
Wenn ich das Programm beende, dann geht die Prozessorauslastung nach oben und es dauert ewig bis es sich beendet.</p>
<p>Ohne</p>
<pre><code class="language-cpp">memDC.FillSolidRect(0, 0, width, height, RGB(255,255,255)); // weisser Hintergrund
</code></pre>
<p>geht's wesentlich schneller, mit dem kleinen Nachteil, dass der Hintergrund schwarz ist <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /></p>
<p>Habt Ihr vielleicht eine Idee, weshalb dieses Problem auftritt? Oder einen Vorschlag/Tipp..</p>
<p>Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/73183/cbitmap</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 06:19:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/73183.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 07 May 2004 05:46:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CBitmap on Fri, 07 May 2004 05:46:23 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe (mal wieder) ein Problem mit Bitmaps:</p>
<pre><code class="language-cpp">CDC     memDC; 
CDC*    pDC = GetDC(); 
CBitmap *pOldBitmap;   

memDC.CreateCompatibleDC(pDC);
(*Bitmap).CreateCompatibleBitmap(pDC, width, height); 
pOldBitmap = memDC.SelectObject(Bitmap); 

const int nXMIN = -100;
const int nXMAX = 100;
const int nYMIN = -100;
const int nYMAX = 100;

// Map-Mode auf LOENGLISH setzen
memDC.SetMapMode(MM_LOENGLISH);

// Neuer Nullpunkt
CPoint     CZero(-nXMIN,nYMIN);
// Verschiebung des Nullpunktes aufgrund Mapping-Mode ausrechnen
memDC.LPtoDP(&amp;CZero);
memDC.SetViewportOrg(CZero);

// Routine für's zeichnen	

memDC.SelectObject(pOldBitmap);
ReleaseDC(&amp;memDC);
</code></pre>
<p>Der Code ist soweit in Ordnung, aber der Hintergrund ist schwarz.</p>
<p>Mit</p>
<pre><code>memDC.FillSolidRect(0, 0, width, height, RGB(255,255,255)); // weisser Hintergrund
</code></pre>
<p>bekomme ich nun einen weissen Hintergrund .. und die Anwendung läuft. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p>Jetzt ist es so, dass die Bitmap ziemlich groß ist. 32467 x 480.<br />
Wenn ich das Programm beende, dann geht die Prozessorauslastung nach oben und es dauert ewig bis es sich beendet.</p>
<p>Ohne</p>
<pre><code class="language-cpp">memDC.FillSolidRect(0, 0, width, height, RGB(255,255,255)); // weisser Hintergrund
</code></pre>
<p>geht's wesentlich schneller, mit dem kleinen Nachteil, dass der Hintergrund schwarz ist <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /></p>
<p>Habt Ihr vielleicht eine Idee, weshalb dieses Problem auftritt? Oder einen Vorschlag/Tipp..</p>
<p>Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/515707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/515707</guid><dc:creator><![CDATA[EdiRitter]]></dc:creator><pubDate>Fri, 07 May 2004 05:46:23 GMT</pubDate></item><item><title><![CDATA[Reply to CBitmap on Fri, 07 May 2004 06:34:53 GMT]]></title><description><![CDATA[<p>hab leider keine ahnung aber ich koennte dir was bitmaps angeht vielleicht mit fertigem code aushelfen<br />
je nachdem was du brauchst...</p>
<p>aber eine frage habe ich: was'n &quot;LOENGLISH&quot;??? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>schau dir vielleicht mal folgenden code an und vielleicht findest du was raus<br />
die int CTest1Dlg::dc2bitmap(HDC hdc, HBITMAP aBmp, LPTSTR szFile2) methode ist fuer screenshots eines ausschnitts in monochrome<br />
und die bool CTest1Dlg::WriteBitmap(LPTSTR szFile, HBITMAP hbitmap, HDC memdc) fuer screenshots in 24bitRGB<br />
schlecht kommentiert da auch erst zusammengewuerfelt aber voll funktionsfaehig</p>
<pre><code>BOOL CTest1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	farbe = RGB(0,0,200);
	xstart=0;
	ystart=150;
	xende= 240;
	yende=269;
	Bild1.LoadBitmap( IDB_BITMAP1 );

	// Set the icon for this dialog.  The framework does this automatically
	// when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);				// Set big icon
	SetIcon(m_hIcon, FALSE);			// Set small icon

	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTest1Dlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	m_VorX=point.x;
	m_VorY=point.y;
	//CDialog::OnLButtonDown(nFlags, point);
	Default();
}

void CTest1Dlg::OnMouseMove(UINT nFlags, CPoint point) 
{	
	CClientDC cc( this );
	if ( m_VorY&gt; (ystart+1))
		{
			if((nFlags&amp; MK_LBUTTON)==MK_LBUTTON)
			{
				CPen *oldpen;
				CClientDC dc(this);
				CPen NeuPen(PS_SOLID,2,farbe);
				oldpen= dc.SelectObject(&amp;NeuPen);

				dc.MoveTo(m_VorX,m_VorY);
				if ( point.y&gt;  (ystart+1))
				{
					dc.LineTo(point.x,point.y);
					m_VorX=point.x;
					m_VorY=point.y;
				}
				dc.SelectObject(oldpen);
				CDialog::OnMouseMove(nFlags, point);
			}
	}

}

void CTest1Dlg::OnExit() 
{
	OnOK();	
}

void CTest1Dlg::OnNeu() 
{	
	Invalidate();
}

void CTest1Dlg::OnPaint() 
{	

	CBrush *brush=new CBrush; 
	brush-&gt;CreateSolidBrush(0x00FFFFFF); 

	//// TRENNSTRICH ZEICHNEN ////
	CPaintDC dc(this);
	CPen *oldpen;
	CPen NeuPen(PS_SOLID,2,RGB(0,0,0));
	oldpen= dc.SelectObject(&amp;NeuPen);
	dc.MoveTo(0,150);
	dc.LineTo(269,150);
	dc.SelectObject(oldpen);
	CDialog::OnPaint(); 
	//////////////////////////////
}
void CTest1Dlg::OnNext() 
{
	CPaintDC pc(this);
	//jetzt das ganze als Bitmap abspeichern 
	CDC *dc=new CDC;				//ein neuer unabhängiger DC 
	CBitmap *membmp=new CBitmap;	//eine Bitmap die den DC representiert 
	RECT cr;						//für die Grösse des Clients 

	dc-&gt;CreateCompatibleDC(GetDC());  
	GetClientRect(&amp;cr);				//Ausdehnung des Clientsbereichs ermitteln 
	//passende Bitmap in der Grösse des Clients anlegen 
	membmp-&gt;CreateCompatibleBitmap(GetDC(), cr.right,cr.bottom); 

	//Speicherkontext mit der Bitmap verbinden 
	dc-&gt;SelectObject(membmp); 
	//In den Speicherkontext (eigentlich in die Bitmap!) den Inhalt des dc kopieren 
	dc-&gt;BitBlt(0,0,cr.right,cr.bottom,GetDC(),0,0,SRCCOPY); 

	//Jetzt die Bitmap speichern 
	//WriteBitmap(_T(&quot;\\testbitmap.bmp&quot;),membmp-&gt;operator HBITMAP(), dc-&gt;m_hDC); 

	int weite = 240;
	int hoehe = 120;

	dc2bitmap(dc-&gt;m_hDC, membmp-&gt;operator HBITMAP(), _T(&quot;\\schwarzweiss.bmp&quot;));

	dc-&gt;DeleteDC(); 
	delete dc; 

	membmp-&gt;DeleteObject(); 
	delete membmp; 
}

int CTest1Dlg::dc2bitmap(HDC hdc, HBITMAP aBmp, LPTSTR szFile2)
{
	int width = 240;			//Breite der zu speichernden Flaeche
	int height = 116;			//Hoehe  der zu speichernden Flaeche
	HDC hdc2;			
    HGDIOBJ OldObj; 
    void *dibvalues; 
    HANDLE fileHandle; 

    BITMAPFILEHEADER bmfh; 

    DWORD bytes_write; 
    DWORD bytes_written; 

    hdc2=CreateCompatibleDC(hdc); 

    DWORD sizeBI = sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD)); 
    LPBITMAPINFO lpbi = (LPBITMAPINFO) new char[sizeBI]; 
    ZeroMemory(lpbi,sizeBI); 

    lpbi-&gt;bmiHeader.biSize        = sizeof(BITMAPINFOHEADER); 
    lpbi-&gt;bmiHeader.biWidth       = width; 
    lpbi-&gt;bmiHeader.biHeight      = height; 
    lpbi-&gt;bmiHeader.biPlanes      = 1; 
    lpbi-&gt;bmiHeader.biBitCount    = 1; 
    lpbi-&gt;bmiHeader.biCompression = BI_RGB; 
    lpbi-&gt;bmiHeader.biSizeImage   = ((((lpbi-&gt;bmiHeader.biWidth * lpbi-&gt;bmiHeader.biBitCount) + 31) &amp; ~31) &gt;&gt; 3) * lpbi-&gt;bmiHeader.biHeight; 

    /*for(int i = 0; i &lt; 256; i++) 
    { 
        lpbi-&gt;bmiColors[i].rgbRed   = i; 
        lpbi-&gt;bmiColors[i].rgbGreen = i; 
        lpbi-&gt;bmiColors[i].rgbBlue  = i; 
    }*/ 

	lpbi-&gt;bmiColors[1].rgbRed   = 255; 
	lpbi-&gt;bmiColors[1].rgbGreen = 255; 
	lpbi-&gt;bmiColors[1].rgbBlue  = 255;

    aBmp = CreateDIBSection(hdc,lpbi,DIB_RGB_COLORS,(void**)&amp;dibvalues,NULL,NULL); 

    if (aBmp==NULL) 
    { 
        OutputDebugString(_T(&quot;CreateDIBSection failed!\n&quot;)); 
        return 0; 
    } 

    OldObj=SelectObject(hdc2,aBmp); 
    BitBlt(hdc2,0,0,width,height,hdc,0,150,SRCCOPY); 

    ZeroMemory(&amp;bmfh,sizeof(BITMAPFILEHEADER)); 
    bmfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeBI; 
    bmfh.bfSize=(lpbi-&gt;bmiHeader.biHeight*lpbi-&gt;bmiHeader.biWidth)+sizeof(BITMAPFILEHEADER)+sizeBI; 
    bmfh.bfType=0x4d42; 

    fileHandle=CreateFile(szFile2,GENERIC_READ | GENERIC_WRITE,(DWORD)0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL); 
    if (fileHandle==INVALID_HANDLE_VALUE) 
    { 
        OutputDebugString(_T(&quot;WriteFile failed!\n&quot;)); 
        return 0; 
    } 

    // Write the BITMAPFILEHEADER 
    bytes_write=sizeof(BITMAPFILEHEADER); 
    if (!WriteFile(fileHandle,(void*)&amp;bmfh,bytes_write,&amp;bytes_written,NULL)) 
    { 
        OutputDebugString(_T(&quot;WriteFile failed!\n&quot;)); 
        return 0; 
    } 

    //Write the BITMAPINFOHEADER 
    bytes_write=sizeBI; 
    if (!WriteFile(fileHandle,(void*)lpbi,bytes_write,&amp;bytes_written,NULL)) 
    { 
        OutputDebugString(_T(&quot;WriteFile failed!\n&quot;)); 
        return 0; 
    } 

    //Write the Color Index Array??? 
    bytes_write=lpbi-&gt;bmiHeader.biSizeImage;//3*bmih.biHeight*bmih.biWidth; 
    if (!WriteFile(fileHandle,(void*)dibvalues,bytes_write,&amp;bytes_written,NULL)) 
    { 
        OutputDebugString(_T(&quot;WriteFile failed!\n&quot;)); 
        return 0; 
    } 

    CloseHandle(fileHandle); 

    DeleteObject(SelectObject(hdc2,OldObj)); 
    DeleteDC(hdc2);

	return 1;
}

bool CTest1Dlg::WriteBitmap(LPTSTR szFile, HBITMAP hbitmap, HDC memdc)
{
	CRect rect;
	GetClientRect(&amp;rect);

	CClientDC dc(this);

	int x = 240*3;				//rect.right*3; // 24Bit pro pixel
	int y = 120;				//rect.bottom;

	char* pixel = new char[x*y];

	// Pixel
	int xpos = 0;
	int ypos = rect.bottom;		//Upside-down format
	int index=0;

//CString test=&quot;&quot;;

	while(ypos&gt;rect.bottom-y)		//0
	{	
		while(xpos&lt;(x/3))				//rect.right)
		{
			// Pixel auslesen und in die einzelnen Farben spalten
			//int dummy = 0;

			COLORREF col_ref = dc.GetPixel(xpos,ypos);

			// Rot
			pixel[index]=(char)(col_ref);
			index++;

			// Grün
			pixel[index]=(char)(col_ref);
			index++;

			// Blau
			pixel[index]=(char)(col_ref);
			index++;

			xpos++;

		}

		xpos=0;
		ypos--;
	}

	BITMAPINFOHEADER infoheader;
	infoheader.biSize=sizeof(infoheader);
	infoheader.biWidth=(x/3);		//rect.right; //150 Breite der Bitmap
	infoheader.biHeight=y;			//rect.bottom; //100 Höhe der Bitmap
	infoheader.biPlanes=1;
	infoheader.biBitCount=1;		//Farbtiefe
	infoheader.biCompression=0;
	infoheader.biSizeImage=0;		//Größe der Bitmap (darf 0 sein)
	infoheader.biXPelsPerMeter=0;
	infoheader.biYPelsPerMeter=0;
	infoheader.biClrUsed=0;			//Alle Farben werden benützt
	infoheader.biClrImportant=0;	//Alle Farben sind Wichtig

	BITMAPFILEHEADER fileheader;
	fileheader.bfType=19778;		//BM - Dateityp
	fileheader.bfSize=x*y+sizeof(infoheader)+sizeof(fileheader);
	fileheader.bfReserved1=0;
	fileheader.bfReserved2=0;
	fileheader.bfOffBits=(DWORD)(sizeof(fileheader)+
	sizeof(infoheader));			//Ab hier: Pixel

	// Auf Festplatte speichern
	CFile file;
	LPTSTR path = _T(&quot;\\bitmap.bmp&quot;);

	if(!file.Open(path,CFile::modeWrite|CFile::modeCreate))
	return false;

	// Fileheader + Infoheader
	file.Write(&amp;fileheader,sizeof(fileheader));
	file.Write(&amp;infoheader,sizeof(infoheader));

	// (hier: Palette für 16-256 Farben)

	int nFullLength=WIDTHBYTES( infoheader.biWidth*infoheader.biBitCount );

	// Pixel
	for(int nLine=0; nLine&lt;y; ++nLine)
	file.Write(&amp;pixel[nLine*x],x);
	file.Write(&amp;pixel[nLine*x],nFullLength-x);

	file.Close();

	delete[] pixel;
	delete memdc;

	return true;
}
</code></pre>
<p>gruss<br />
Guenni</p>
]]></description><link>https://www.c-plusplus.net/forum/post/515716</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/515716</guid><dc:creator><![CDATA[Guenter Mies]]></dc:creator><pubDate>Fri, 07 May 2004 06:34:53 GMT</pubDate></item><item><title><![CDATA[Reply to CBitmap on Fri, 07 May 2004 06:44:12 GMT]]></title><description><![CDATA[<p>Super, Danke. Ich werd's mir anschauen..</p>
<p>LOENGLISH = LOW ENGLISH !? :p Es existieren noch weitere Map Modes, darunter auch MM_HIENGLISH. Die Map Modes definieren den Abbildungsmaßstab + Koordinatenrichtung. Bei MM_LOENGLISH entspricht eine logische Einheit 0,01 inch.</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/515725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/515725</guid><dc:creator><![CDATA[EdiRitter]]></dc:creator><pubDate>Fri, 07 May 2004 06:44:12 GMT</pubDate></item><item><title><![CDATA[Reply to CBitmap on Fri, 07 May 2004 07:03:36 GMT]]></title><description><![CDATA[<p>und so hab ich wieder was gelernt.... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>ich sehe grade dass ich noch den BITCOUNT in der 24Bit Methode auf 1 anstatt 24 habe<br />
koennten noch weitere kleine fehler in der 24bit methode uebrig sein da ich noch dran rumgepfuscht hatte...sorry</p>
<p>gruss<br />
Guenni</p>
]]></description><link>https://www.c-plusplus.net/forum/post/515736</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/515736</guid><dc:creator><![CDATA[Guenter Mies]]></dc:creator><pubDate>Fri, 07 May 2004 07:03:36 GMT</pubDate></item></channel></rss>