Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. bitmaps & regions [modified]

bitmaps & regions [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsdebuggingtutorialquestionlearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zqueezy
    wrote on last edited by
    #1

    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 resource

    BITMAP bBitmap;
    bg_Image.GetBitmap(&bBitmap); // load bitmap data

    BYTE *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 region

    CRgn 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

    M Z 2 Replies Last reply
    0
    • Z zqueezy

      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 resource

      BITMAP bBitmap;
      bg_Image.GetBitmap(&bBitmap); // load bitmap data

      BYTE *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 region

      CRgn 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

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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:

      1 Reply Last reply
      0
      • Z zqueezy

        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 resource

        BITMAP bBitmap;
        bg_Image.GetBitmap(&bBitmap); // load bitmap data

        BYTE *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 region

        CRgn 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

        Z Offline
        Z Offline
        zqueezy
        wrote on last edited by
        #3

        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
        

        }

        M 1 Reply Last reply
        0
        • Z zqueezy

          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
          

          }

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups