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. ¿Quién sabe? alphablending 2 bitmaps

¿Quién sabe? alphablending 2 bitmaps

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestion
5 Posts 3 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.
  • C Offline
    C Offline
    Chesnokov Yuriy
    wrote on last edited by
    #1

    There 2 32bpp bitmaps with some images: bitmap1 bitmap2 and graphics object g1 created from bitmap1 I set individualy alpha values in bitmap2 using LockBits:

        Gdiplus::BitmapData bitmapData;
        Gdiplus::Status s = pBitmap->LockBits(&Gdiplus::Rect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()),
                                              Gdiplus::ImageLockModeWrite | Gdiplus::ImageLockModeRead,
                                              PixelFormat32bppRGB, &bitmapData);
        if (s == Gdiplus::Ok) {                
                unsigned int\* pPixels = (unsigned int \*)bitmapData.Scan0;
                for (unsigned int i = 0; i < bitmapData.Height; i++) {                        
                        for (unsigned int j = 0; j < bitmapData.Width; j++) {
                                if (mask(i, j) > 0)
                                        pPixels\[j\] &= 0xFFFFFFFF;
                                else
                                        pPixels\[j\] = 0x00FFFFFF;
                        }                        
                        pPixels += bitmapData.Stride / 4;
                }                                
                pBitmap->UnlockBits(&bitmapData);
        }
    

    And then draw it on bitmap1 using g1. But the alpha blending does not happen?

    chesnokov

    C G 2 Replies Last reply
    0
    • C Chesnokov Yuriy

      There 2 32bpp bitmaps with some images: bitmap1 bitmap2 and graphics object g1 created from bitmap1 I set individualy alpha values in bitmap2 using LockBits:

          Gdiplus::BitmapData bitmapData;
          Gdiplus::Status s = pBitmap->LockBits(&Gdiplus::Rect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()),
                                                Gdiplus::ImageLockModeWrite | Gdiplus::ImageLockModeRead,
                                                PixelFormat32bppRGB, &bitmapData);
          if (s == Gdiplus::Ok) {                
                  unsigned int\* pPixels = (unsigned int \*)bitmapData.Scan0;
                  for (unsigned int i = 0; i < bitmapData.Height; i++) {                        
                          for (unsigned int j = 0; j < bitmapData.Width; j++) {
                                  if (mask(i, j) > 0)
                                          pPixels\[j\] &= 0xFFFFFFFF;
                                  else
                                          pPixels\[j\] = 0x00FFFFFF;
                          }                        
                          pPixels += bitmapData.Stride / 4;
                  }                                
                  pBitmap->UnlockBits(&bitmapData);
          }
      

      And then draw it on bitmap1 using g1. But the alpha blending does not happen?

      chesnokov

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I don't see where you're doing any alpha blending. Alpha blending would mean blending the values of two bitmaps. What are you trying to do ? Also, have you stepped through the code to see if mask(i,j) is ever > 0 ? I assume that mask is a method, calling a method for every pixel will really slow your code down.

      Christian Graus Driven to the arms of OSX by Vista.

      C 2 Replies Last reply
      0
      • C Christian Graus

        I don't see where you're doing any alpha blending. Alpha blending would mean blending the values of two bitmaps. What are you trying to do ? Also, have you stepped through the code to see if mask(i,j) is ever > 0 ? I assume that mask is a method, calling a method for every pixel will really slow your code down.

        Christian Graus Driven to the arms of OSX by Vista.

        C Offline
        C Offline
        Chesnokov Yuriy
        wrote on last edited by
        #3

        sure. mask is a unsigned int version of http://www.codeproject.com/KB/recipes/SSE_optimized_2D_vector.aspx[^] it is inline operator(y,x) for m_data[y][x]. it has print() function so you can view its contents before hand. I need to turn off some pixels in bitmap2 by setting their A values to 0, so if you draw it to bitmap2, the pixels with A = 0 will not affect bitmap1 pixels

        chesnokov

        1 Reply Last reply
        0
        • C Christian Graus

          I don't see where you're doing any alpha blending. Alpha blending would mean blending the values of two bitmaps. What are you trying to do ? Also, have you stepped through the code to see if mask(i,j) is ever > 0 ? I assume that mask is a method, calling a method for every pixel will really slow your code down.

          Christian Graus Driven to the arms of OSX by Vista.

          C Offline
          C Offline
          Chesnokov Yuriy
          wrote on last edited by
          #4

          BTW you work in vet telemedicine, do they collect/transfer ECGs? http://www.codeproject.com/KB/library/ECG_annotation_lib.aspx[^] It might be useful for some wealthy clients of having a dog or a cat with ECG recorder say predicting PAF onset?

          Чесноков

          1 Reply Last reply
          0
          • C Chesnokov Yuriy

            There 2 32bpp bitmaps with some images: bitmap1 bitmap2 and graphics object g1 created from bitmap1 I set individualy alpha values in bitmap2 using LockBits:

                Gdiplus::BitmapData bitmapData;
                Gdiplus::Status s = pBitmap->LockBits(&Gdiplus::Rect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()),
                                                      Gdiplus::ImageLockModeWrite | Gdiplus::ImageLockModeRead,
                                                      PixelFormat32bppRGB, &bitmapData);
                if (s == Gdiplus::Ok) {                
                        unsigned int\* pPixels = (unsigned int \*)bitmapData.Scan0;
                        for (unsigned int i = 0; i < bitmapData.Height; i++) {                        
                                for (unsigned int j = 0; j < bitmapData.Width; j++) {
                                        if (mask(i, j) > 0)
                                                pPixels\[j\] &= 0xFFFFFFFF;
                                        else
                                                pPixels\[j\] = 0x00FFFFFF;
                                }                        
                                pPixels += bitmapData.Stride / 4;
                        }                                
                        pBitmap->UnlockBits(&bitmapData);
                }
            

            And then draw it on bitmap1 using g1. But the alpha blending does not happen?

            chesnokov

            G Offline
            G Offline
            Gabriel P G
            wrote on last edited by
            #5

            Shouldn´t the PixelFormat be PixelFormat32bppARGB instead of PixelFormat32bppRGB?

            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