<?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[Probleme mit SetDIBitsToDevice]]></title><description><![CDATA[<p>hallo,</p>
<p>ich programmiere einen einfachen ColorPicker und habe das Problem, dass mein Pickerfield gedreht angezeigt wird m wärend die MouseMove Funktion korrekt ist.<br />
Wenn ich also einen einfachen Gradienten erzeuge, der von Oben Rot nach Unten Schwarz wird, dann wird mir der falsche Wert angezeigt.</p>
<p>CODE:</p>
<p>im Header habe ich definiert:</p>
<pre><code class="language-cpp">private:
	COLORREF m_crData[320*240];
	BITMAPINFO m_bmi;
</code></pre>
<p>im Oninit habe ich folgenden Code:</p>
<pre><code class="language-cpp">for(int y = 240 - 1; y &gt;=0; y--) //lines
	{
		for(int x = 0; x &lt; 320; x++)
		{		
			this-&gt;m_crData[y * 320 + x] = RGB(y*240/255, x*255/320, 64);
		}
	}

	ZeroMemory(&amp;m_bmi, sizeof(BITMAPINFO));

	this-&gt;m_bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	this-&gt;m_bmi.bmiHeader.biWidth = 320;
	this-&gt;m_bmi.bmiHeader.biHeight = 240;
 	this-&gt;m_bmi.bmiHeader.biPlanes = 1;
	this-&gt;m_bmi.bmiHeader.biBitCount = 32;
	this-&gt;m_bmi.bmiHeader.biCompression = BI_RGB;
</code></pre>
<p>in der OnPaintanweisung steht dann:</p>
<pre><code class="language-cpp">if(!SetDIBitsToDevice(dc, 20, 20, 320, 240, 0, 0, 0, 320, this-&gt;m_crData, &amp;this-&gt;m_bmi, DIB_RGB_COLORS))AfxMessageBox(&quot;ERROR&quot;);
</code></pre>
<p>in WM_MouseMove</p>
<pre><code class="language-cpp">CString str;
	int pos_x, pos_y;

	pos_x = point.x - 20; //rand
	pos_y = point.y - 20; //rand

	if(pos_x &gt;= 0 &amp;&amp; pos_x &lt; 320 &amp;&amp; pos_y &gt;= 0 &amp;&amp; pos_y &lt; 240)
	{
		COLORREF cr = this-&gt;m_crData[pos_y * 320 + pos_x];
		str.Format(&quot;RGB = {%lu, %lu, %lu}&quot;, (DWORD)GetRValue(cr), (DWORD)GetGValue(cr), (DWORD)GetBValue(cr)); 	}
	else
	{
		str = &quot;Keine Pixeldaten hier!&quot;;
	}

	this-&gt;SetWindowText(str);
</code></pre>
<p>vielen Dank für Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/84534/probleme-mit-setdibitstodevice</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 14:35:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/84534.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 31 Aug 2004 11:08:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme mit SetDIBitsToDevice on Tue, 31 Aug 2004 11:09:44 GMT]]></title><description><![CDATA[<p>hallo,</p>
<p>ich programmiere einen einfachen ColorPicker und habe das Problem, dass mein Pickerfield gedreht angezeigt wird m wärend die MouseMove Funktion korrekt ist.<br />
Wenn ich also einen einfachen Gradienten erzeuge, der von Oben Rot nach Unten Schwarz wird, dann wird mir der falsche Wert angezeigt.</p>
<p>CODE:</p>
<p>im Header habe ich definiert:</p>
<pre><code class="language-cpp">private:
	COLORREF m_crData[320*240];
	BITMAPINFO m_bmi;
</code></pre>
<p>im Oninit habe ich folgenden Code:</p>
<pre><code class="language-cpp">for(int y = 240 - 1; y &gt;=0; y--) //lines
	{
		for(int x = 0; x &lt; 320; x++)
		{		
			this-&gt;m_crData[y * 320 + x] = RGB(y*240/255, x*255/320, 64);
		}
	}

	ZeroMemory(&amp;m_bmi, sizeof(BITMAPINFO));

	this-&gt;m_bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	this-&gt;m_bmi.bmiHeader.biWidth = 320;
	this-&gt;m_bmi.bmiHeader.biHeight = 240;
 	this-&gt;m_bmi.bmiHeader.biPlanes = 1;
	this-&gt;m_bmi.bmiHeader.biBitCount = 32;
	this-&gt;m_bmi.bmiHeader.biCompression = BI_RGB;
</code></pre>
<p>in der OnPaintanweisung steht dann:</p>
<pre><code class="language-cpp">if(!SetDIBitsToDevice(dc, 20, 20, 320, 240, 0, 0, 0, 320, this-&gt;m_crData, &amp;this-&gt;m_bmi, DIB_RGB_COLORS))AfxMessageBox(&quot;ERROR&quot;);
</code></pre>
<p>in WM_MouseMove</p>
<pre><code class="language-cpp">CString str;
	int pos_x, pos_y;

	pos_x = point.x - 20; //rand
	pos_y = point.y - 20; //rand

	if(pos_x &gt;= 0 &amp;&amp; pos_x &lt; 320 &amp;&amp; pos_y &gt;= 0 &amp;&amp; pos_y &lt; 240)
	{
		COLORREF cr = this-&gt;m_crData[pos_y * 320 + pos_x];
		str.Format(&quot;RGB = {%lu, %lu, %lu}&quot;, (DWORD)GetRValue(cr), (DWORD)GetGValue(cr), (DWORD)GetBValue(cr)); 	}
	else
	{
		str = &quot;Keine Pixeldaten hier!&quot;;
	}

	this-&gt;SetWindowText(str);
</code></pre>
<p>vielen Dank für Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/595936</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/595936</guid><dc:creator><![CDATA[equal]]></dc:creator><pubDate>Tue, 31 Aug 2004 11:09:44 GMT</pubDate></item></channel></rss>