How to AddAlpha Values ??
-
How can i change alpha channel values without rinning Height*width loop Is there any way that i can drawimage without altering alpha values of background??. i mean i have two images where bye sequences of pixels will be as follows 22 0 34 0 56 0 255 14 55 0 22 0 44 0 255 10 23 0 37 0 56 0 255 14 51 0 28 0 44 0 255 10 now i want to replace 255 with other values or Replace 0's with values from first column.
-
How can i change alpha channel values without rinning Height*width loop Is there any way that i can drawimage without altering alpha values of background??. i mean i have two images where bye sequences of pixels will be as follows 22 0 34 0 56 0 255 14 55 0 22 0 44 0 255 10 23 0 37 0 56 0 255 14 51 0 28 0 44 0 255 10 now i want to replace 255 with other values or Replace 0's with values from first column.
I'm confused. How does a drawimage alter alpha values of a background?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
I'm confused. How does a drawimage alter alpha values of a background?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
If i create the graphics object from a bitmap object which has some alpha values. Now using this graphics object if i draw some other bitmap on firstbitmap the alpha values are altered i mean they will be set to 255.
Gotcha. Since there's only two compositing modes, you may have to loop through and combine the alpha values the way you want to.
SandipG wrote:
now i want to replace 255 with other values or Replace 0's with values from first column.
CompositingModeSourceOver works for the "Replace 0's with values from first column" case but not for the "replace 255 with other values" case. Here's some code you can play with to see the compositing results...
// Create a 20x20 ARGB bitmap
Gdiplus::Bitmap Bitmap1(20, 20, PixelFormat32bppARGB);Gdiplus::Rect rect(0, 0, 20, 20);
// Create a Graphics object from the bitmap
Gdiplus::Graphics *pBitmapGraphics1 = Gdiplus::Graphics::FromImage(&Bitmap1);// Try different compositing modes
//pBitmapGraphics1->SetCompositingMode(Gdiplus::CompositingModeSourceCopy);
pBitmapGraphics1->SetCompositingMode(Gdiplus::CompositingModeSourceOver);// Try different colors to blend - brush is background, pen is foreground
Gdiplus::SolidBrush solidbrush(Gdiplus::Color(0xFF,0x00,0xFF,0x00));//Gdiplus::Color::Transparent);
Gdiplus::Pen solidpen(Gdiplus::Color(0x40,0xFF,0x00,0x00), 1.0);//Gdiplus::Color::Transparent, 1.0);// Fill the background with the brush color and draw the first row with the pen, using
// the current compositing mode
pBitmapGraphics1->FillRectangle(&solidbrush, rect);
pBitmapGraphics1->DrawLine(&solidpen, 0, 0, 19, 0);// Release the bitmap from the graphics object so we can look at the pixel bits
delete pBitmapGraphics1;
pBitmapGraphics1 = 0;// Look at the pixel bits (look at pRGBQuads in a debugger memory window)
Gdiplus::BitmapData bitmapData;
Bitmap1.LockBits(&rect, ImageLockModeRead, PixelFormat32bppARGB, &bitmapData);
RGBQUAD *pRGBQuads = (RGBQUAD *)bitmapData.Scan0;
Bitmap1.UnlockBits(&bitmapData); //<-- put breakpoint here
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Gotcha. Since there's only two compositing modes, you may have to loop through and combine the alpha values the way you want to.
SandipG wrote:
now i want to replace 255 with other values or Replace 0's with values from first column.
CompositingModeSourceOver works for the "Replace 0's with values from first column" case but not for the "replace 255 with other values" case. Here's some code you can play with to see the compositing results...
// Create a 20x20 ARGB bitmap
Gdiplus::Bitmap Bitmap1(20, 20, PixelFormat32bppARGB);Gdiplus::Rect rect(0, 0, 20, 20);
// Create a Graphics object from the bitmap
Gdiplus::Graphics *pBitmapGraphics1 = Gdiplus::Graphics::FromImage(&Bitmap1);// Try different compositing modes
//pBitmapGraphics1->SetCompositingMode(Gdiplus::CompositingModeSourceCopy);
pBitmapGraphics1->SetCompositingMode(Gdiplus::CompositingModeSourceOver);// Try different colors to blend - brush is background, pen is foreground
Gdiplus::SolidBrush solidbrush(Gdiplus::Color(0xFF,0x00,0xFF,0x00));//Gdiplus::Color::Transparent);
Gdiplus::Pen solidpen(Gdiplus::Color(0x40,0xFF,0x00,0x00), 1.0);//Gdiplus::Color::Transparent, 1.0);// Fill the background with the brush color and draw the first row with the pen, using
// the current compositing mode
pBitmapGraphics1->FillRectangle(&solidbrush, rect);
pBitmapGraphics1->DrawLine(&solidpen, 0, 0, 19, 0);// Release the bitmap from the graphics object so we can look at the pixel bits
delete pBitmapGraphics1;
pBitmapGraphics1 = 0;// Look at the pixel bits (look at pRGBQuads in a debugger memory window)
Gdiplus::BitmapData bitmapData;
Bitmap1.LockBits(&rect, ImageLockModeRead, PixelFormat32bppARGB, &bitmapData);
RGBQUAD *pRGBQuads = (RGBQUAD *)bitmapData.Scan0;
Bitmap1.UnlockBits(&bitmapData); //<-- put breakpoint here
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
I played with it but it works with pens and brushes only. No change in effect of DrawImage.
With DrawImage(), on the destination Graphics... SetCompositingMode(CompositingModeSourceCopy) will cause the drawn image to replace whatever was in the destination image. SetCompositingMode(CompositingModeSourceOver) will cause the drawn image to be blended with whatever was in the destination image (the resulting alpha values are not always set to 255). You should get the same results as with a pen and a brush. A bitmap filled with values with alpha set to 0 drawn on an image with alpha set to, say, 0x80, will leave the destination alpha 80. That matches your replace 0s with the first column alpha value, just like with a brush or pen. Regardless, I guess my point was that to get the results you want with the alpha channels, I don't believe the APIs are going to do it. Even though you were looking to avoid it, LockBits/UnlockBits makes it relatively trivial to loop through the images and combine them yourself. Mark -- modified at 13:09 Monday 25th June, 2007
"Go that way, really fast. If something gets in your way, turn."