Changing pixel color on a bitmap
-
I have a button on my CFormView with a bitmap. How can I change the color of each individual pixel in the bitmap?
-
I have a button on my CFormView with a bitmap. How can I change the color of each individual pixel in the bitmap?
dwccgc wrote: How can I change the color of each individual pixel in the bitmap? Select it into a device context and use
SetPixel()
orSetPixelV()
, the latter being the fastest.Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
dwccgc wrote: How can I change the color of each individual pixel in the bitmap? Select it into a device context and use
SetPixel()
orSetPixelV()
, the latter being the fastest.Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
I need to get the current color before I use SetPixel(..), but I cannot get GetPixel() to work. pDc->GetPixel() returns -1. Maybe I am missing something. Note: m_ExitButtonCtrl is of type CButton. hbmButtonExit is of type HBITMAP.
void CMyFormView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();// Load BitMap hbmButtonExit = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB\_BUTTON\_EXIT)); if (hbmButtonExit != NULL) { m\_ExitButtonCtrl.SetBitmap(hbmButtonExit); CDC \*pDc = m\_ExitButtonCtrl.GetDC(); if (pDc != NULL) { for (INT nX = 0; nX < 69; nX++) { for (INT nY = 0; nY < 47; nY++) { COLORREF OrgColor = **pDc->GetPixel(nX, nY);** } } } } return;
}
-
I need to get the current color before I use SetPixel(..), but I cannot get GetPixel() to work. pDc->GetPixel() returns -1. Maybe I am missing something. Note: m_ExitButtonCtrl is of type CButton. hbmButtonExit is of type HBITMAP.
void CMyFormView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();// Load BitMap hbmButtonExit = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB\_BUTTON\_EXIT)); if (hbmButtonExit != NULL) { m\_ExitButtonCtrl.SetBitmap(hbmButtonExit); CDC \*pDc = m\_ExitButtonCtrl.GetDC(); if (pDc != NULL) { for (INT nX = 0; nX < 69; nX++) { for (INT nY = 0; nY < 47; nY++) { COLORREF OrgColor = **pDc->GetPixel(nX, nY);** } } } } return;
}
You need to select the bitmap into a device context.
void CMyFormView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
hbmButtonExit = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BUTTON_EXIT));
if (hbmButtonExit != NULL)
{
CClientDC dc(this);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap *pBitmap = memDC.SelectObject(CBitmap::FromHandle(hbmButtonExit));
for (INT nX = 0; nX < 69; nX++)
{
for (INT nY = 0; nY < 47; nY++)
{
COLORREF OrgColor = memDC.GetPixel(nX, nY);
// Do whatever else here
}
}
memDC.SelectObject(pBitmap);
m_ExitButtonCtrl.SetBitmap(hbmButtonExit);
}
}Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
You need to select the bitmap into a device context.
void CMyFormView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
hbmButtonExit = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BUTTON_EXIT));
if (hbmButtonExit != NULL)
{
CClientDC dc(this);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap *pBitmap = memDC.SelectObject(CBitmap::FromHandle(hbmButtonExit));
for (INT nX = 0; nX < 69; nX++)
{
for (INT nY = 0; nY < 47; nY++)
{
COLORREF OrgColor = memDC.GetPixel(nX, nY);
// Do whatever else here
}
}
memDC.SelectObject(pBitmap);
m_ExitButtonCtrl.SetBitmap(hbmButtonExit);
}
}Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
Thanks for the help.:)
-
Thanks for the help.:)
You're welcome :)
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"