bitmaps & regions [modified]
-
hey folks, I've got a little snippet I wanna use to do a splash screen from a mask-image (2-bit image). well... it doesn't work
CBitmap bg_Image; // create Image
bg_Image.LoadBitmap(IDB_BITMAP1); // load from resourceBITMAP bBitmap;
bg_Image.GetBitmap(&bBitmap); // load bitmap dataBYTE *pBuffer = new BYTE[bBitmap.bmWidth * bBitmap.bmHeight];
bg_Image.GetBitmapBits(bBitmap.bmHeight*bBitmap.bmWidth, pBuffer);
CRgn newRegion; // new region for dialog
newRegion.CreateRectRgn(0,0,0,0); // creat empty regionCRgn tmpRgn; // temporary region
for (int y=1; y< bBitmap.bmHeight; ++y)
{
for (int x=1; x < bBitmap.bmWidth; ++x)
{
BYTE c = pBuffer[(y)*bBitmap.bmWidth + x];
if (c == 255) // white
{
tmpRgn.DeleteObject(); // clear out region
tmpRgn.CreateRectRgn(x,y,x+1,y+1);
newRegion.CombineRgn(&newRegion, &tmpRgn, RGN_OR);
}}
}
this->SetWindowRgn(newRegion, true);delete [] pBuffer;
The result is nothing near what I expected... some ragged & jagged dialog. when I set a breakpoint on "tmpRgn.CreateRectRgn(x,y,x+1,y+1);" I find that the x and y of the for-loop is not what it should be in the image!!! any hints on how to do my splash-screen? thx in advance zqueezy -- modified at 20:58 Thursday 6th September, 2007
-
hey folks, I've got a little snippet I wanna use to do a splash screen from a mask-image (2-bit image). well... it doesn't work
CBitmap bg_Image; // create Image
bg_Image.LoadBitmap(IDB_BITMAP1); // load from resourceBITMAP bBitmap;
bg_Image.GetBitmap(&bBitmap); // load bitmap dataBYTE *pBuffer = new BYTE[bBitmap.bmWidth * bBitmap.bmHeight];
bg_Image.GetBitmapBits(bBitmap.bmHeight*bBitmap.bmWidth, pBuffer);
CRgn newRegion; // new region for dialog
newRegion.CreateRectRgn(0,0,0,0); // creat empty regionCRgn tmpRgn; // temporary region
for (int y=1; y< bBitmap.bmHeight; ++y)
{
for (int x=1; x < bBitmap.bmWidth; ++x)
{
BYTE c = pBuffer[(y)*bBitmap.bmWidth + x];
if (c == 255) // white
{
tmpRgn.DeleteObject(); // clear out region
tmpRgn.CreateRectRgn(x,y,x+1,y+1);
newRegion.CombineRgn(&newRegion, &tmpRgn, RGN_OR);
}}
}
this->SetWindowRgn(newRegion, true);delete [] pBuffer;
The result is nothing near what I expected... some ragged & jagged dialog. when I set a breakpoint on "tmpRgn.CreateRectRgn(x,y,x+1,y+1);" I find that the x and y of the for-loop is not what it should be in the image!!! any hints on how to do my splash-screen? thx in advance zqueezy -- modified at 20:58 Thursday 6th September, 2007
All the code looks like it's for 8-bit images only (and assumes a WORD aligned width). If the source bitmap is not 8-bitsperpixel, then you need to use bBitmap.bmWidthBytes instead of bBitmap.bmWidth when calculating array size and offset of pixel in buffer. Plus, if it's < 8 bpp, you need to mask out the appropriate bits to match the color. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
hey folks, I've got a little snippet I wanna use to do a splash screen from a mask-image (2-bit image). well... it doesn't work
CBitmap bg_Image; // create Image
bg_Image.LoadBitmap(IDB_BITMAP1); // load from resourceBITMAP bBitmap;
bg_Image.GetBitmap(&bBitmap); // load bitmap dataBYTE *pBuffer = new BYTE[bBitmap.bmWidth * bBitmap.bmHeight];
bg_Image.GetBitmapBits(bBitmap.bmHeight*bBitmap.bmWidth, pBuffer);
CRgn newRegion; // new region for dialog
newRegion.CreateRectRgn(0,0,0,0); // creat empty regionCRgn tmpRgn; // temporary region
for (int y=1; y< bBitmap.bmHeight; ++y)
{
for (int x=1; x < bBitmap.bmWidth; ++x)
{
BYTE c = pBuffer[(y)*bBitmap.bmWidth + x];
if (c == 255) // white
{
tmpRgn.DeleteObject(); // clear out region
tmpRgn.CreateRectRgn(x,y,x+1,y+1);
newRegion.CombineRgn(&newRegion, &tmpRgn, RGN_OR);
}}
}
this->SetWindowRgn(newRegion, true);delete [] pBuffer;
The result is nothing near what I expected... some ragged & jagged dialog. when I set a breakpoint on "tmpRgn.CreateRectRgn(x,y,x+1,y+1);" I find that the x and y of the for-loop is not what it should be in the image!!! any hints on how to do my splash-screen? thx in advance zqueezy -- modified at 20:58 Thursday 6th September, 2007
so for anybody who's intrested and for the sake of completeness:
BOOL CMeineFormDlg::OnInitDialog()
{
CDialog::OnInitDialog();// Symbol für dieses Dialogfeld festlegen. Wird automatisch erledigt // wenn das Hauptfenster der Anwendung kein Dialogfeld ist SetIcon(m\_hIcon, TRUE); // Großes Symbol verwenden SetIcon(m\_hIcon, FALSE); // Kleines Symbol verwenden // TODO: Hier zusätzliche Initialisierung einfügen CBitmap bg\_Image; // Bild erstellen bg\_Image.LoadBitmap(IDB\_BITMAP1); // Bild aus Resource laden BITMAP bBitmap; // Damit man auf die Daten des Bitmap zugreifen kann bg\_Image.GetBitmap(&bBitmap); // Daten reinladen aus dem CBitmap int iByteSize = bBitmap.bmWidthBytes \* bBitmap.bmHeight \* (bBitmap.bmBitsPixel/8); BYTE \*pBuffer = new BYTE\[iByteSize\]; bg\_Image.GetBitmapBits(iByteSize, pBuffer); CRgn newRgn; // Eine neue Region für den Dialog newRgn.CreateRectRgn(0,0,0,0); CRgn tmpRgn; // Eine Temporäre Region int iOffset = bBitmap.bmBitsPixel/8; int r,g,b,c; for (int y=0; y< bBitmap.bmHeight; ++y) { for (int x=0; x < bBitmap.bmWidth; ++x) { c = y\*bBitmap.bmWidthBytes + x\*iOffset; r = pBuffer\[c+2\]; g = pBuffer\[c+1\]; b = pBuffer\[c\]; if (r == 255 && g == 255 && b == 255) // weiß { tmpRgn.DeleteObject(); // Die Region erstmal leer machen tmpRgn.CreateRectRgn(x,y,x+1,y+1); newRgn.CombineRgn(&newRgn, &tmpRgn, RGN\_OR); } } } this->SetWindowRgn(newRgn, true); delete \[\] pBuffer; return TRUE; // Geben Sie TRUE zurück, außer ein Steuerelement soll den Fokus erhalten
}
-
so for anybody who's intrested and for the sake of completeness:
BOOL CMeineFormDlg::OnInitDialog()
{
CDialog::OnInitDialog();// Symbol für dieses Dialogfeld festlegen. Wird automatisch erledigt // wenn das Hauptfenster der Anwendung kein Dialogfeld ist SetIcon(m\_hIcon, TRUE); // Großes Symbol verwenden SetIcon(m\_hIcon, FALSE); // Kleines Symbol verwenden // TODO: Hier zusätzliche Initialisierung einfügen CBitmap bg\_Image; // Bild erstellen bg\_Image.LoadBitmap(IDB\_BITMAP1); // Bild aus Resource laden BITMAP bBitmap; // Damit man auf die Daten des Bitmap zugreifen kann bg\_Image.GetBitmap(&bBitmap); // Daten reinladen aus dem CBitmap int iByteSize = bBitmap.bmWidthBytes \* bBitmap.bmHeight \* (bBitmap.bmBitsPixel/8); BYTE \*pBuffer = new BYTE\[iByteSize\]; bg\_Image.GetBitmapBits(iByteSize, pBuffer); CRgn newRgn; // Eine neue Region für den Dialog newRgn.CreateRectRgn(0,0,0,0); CRgn tmpRgn; // Eine Temporäre Region int iOffset = bBitmap.bmBitsPixel/8; int r,g,b,c; for (int y=0; y< bBitmap.bmHeight; ++y) { for (int x=0; x < bBitmap.bmWidth; ++x) { c = y\*bBitmap.bmWidthBytes + x\*iOffset; r = pBuffer\[c+2\]; g = pBuffer\[c+1\]; b = pBuffer\[c\]; if (r == 255 && g == 255 && b == 255) // weiß { tmpRgn.DeleteObject(); // Die Region erstmal leer machen tmpRgn.CreateRectRgn(x,y,x+1,y+1); newRgn.CombineRgn(&newRgn, &tmpRgn, RGN\_OR); } } } this->SetWindowRgn(newRgn, true); delete \[\] pBuffer; return TRUE; // Geben Sie TRUE zurück, außer ein Steuerelement soll den Fokus erhalten
}
zqueezy wrote:
int iByteSize = bBitmap.bmWidthBytes * bBitmap.bmHeight * (bBitmap.bmBitsPixel/8);
...as long as you only use bitmaps witha format >= 8 bitsperpixel :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: