@@ -3952,3 +3952,121 @@ long CMiniWindow::DrawImageAlpha(LPCTSTR ImageId,
3952
3952
3953
3953
3954
3954
} // end of CMiniWindow::DrawImageAlpha
3955
+
3956
+ long CMiniWindow::GetImageAlpha (LPCTSTR ImageId,
3957
+ long Left, long Top, long Right, long Bottom,
3958
+ long SrcLeft, long SrcTop)
3959
+ {
3960
+
3961
+ // constrain to what we actually have
3962
+ if (Left < 0 )
3963
+ Left = 0 ;
3964
+ if (Top < 0 )
3965
+ Top = 0 ;
3966
+ if (Right > m_iWidth)
3967
+ Right = m_iWidth;
3968
+ if (Bottom > m_iHeight)
3969
+ Bottom = m_iHeight;
3970
+
3971
+ // image to be merged
3972
+ ImageMapIterator it = m_Images.find (ImageId);
3973
+
3974
+ if (it == m_Images.end ())
3975
+ return eImageNotInstalled;
3976
+
3977
+ CBitmap * bitmap = it->second ;
3978
+
3979
+
3980
+ BITMAP bi;
3981
+ bitmap->GetBitmap (&bi);
3982
+
3983
+ // can't do it unless we have alpha channel
3984
+ if (bi.bmBitsPixel != 32 )
3985
+ return eImageNotInstalled;
3986
+
3987
+ // calculate size of desired rectangle
3988
+ long iWidth = FixRight (Right) - Left;
3989
+ long iHeight = FixBottom (Bottom) - Top;
3990
+
3991
+ // constrain to what we actually have
3992
+ if (SrcLeft < 0 )
3993
+ SrcLeft = 0 ;
3994
+ if (SrcTop < 0 )
3995
+ SrcTop = 0 ;
3996
+
3997
+ if (iWidth <= 0 || iHeight <= 0 ) // sanity check
3998
+ return eOK;
3999
+
4000
+ // merge layer (from image id)
4001
+ CDC A_DC;
4002
+ A_DC.CreateCompatibleDC (&dc);
4003
+
4004
+ BITMAPINFO bmi;
4005
+ ZeroMemory (&bmi, sizeof bmi);
4006
+
4007
+ bmi.bmiHeader .biSize = sizeof bmi;
4008
+ bmi.bmiHeader .biWidth = iWidth;
4009
+ bmi.bmiHeader .biHeight = iHeight;
4010
+ bmi.bmiHeader .biPlanes = 1 ;
4011
+ bmi.bmiHeader .biBitCount = 32 ;
4012
+ bmi.bmiHeader .biCompression = BI_RGB;
4013
+ bmi.bmiHeader .biSizeImage = iHeight * BytesPerLine (iWidth, 32 );
4014
+
4015
+ unsigned char * pA = NULL ;
4016
+
4017
+ HBITMAP hbmA = CreateDIBSection (NULL , &bmi, DIB_RGB_COLORS, (void **) &pA, NULL , 0 );
4018
+
4019
+ HBITMAP hOldAbmp = (HBITMAP) SelectObject (A_DC.m_hDC , hbmA);
4020
+
4021
+ CDC bmDC; // for loading bitmaps into
4022
+ bmDC.CreateCompatibleDC (&dc);
4023
+
4024
+ // copy part from image to upper layer
4025
+ CBitmap *pOldbmp = bmDC.SelectObject (bitmap);
4026
+ A_DC.BitBlt (0 , 0 , iWidth, iHeight, &bmDC, SrcLeft, SrcTop, SRCCOPY);
4027
+ bmDC.SelectObject (pOldbmp);
4028
+
4029
+
4030
+ // base image (from miniwindow)
4031
+
4032
+ CDC B_DC;
4033
+ B_DC.CreateCompatibleDC (&dc);
4034
+ CBitmap B_bmp;
4035
+
4036
+ unsigned char * pB = NULL ;
4037
+
4038
+ HBITMAP hbmB = CreateDIBSection (NULL , &bmi, DIB_RGB_COLORS, (void **) &pB, NULL , 0 );
4039
+
4040
+ HBITMAP hOldBbmp = (HBITMAP) SelectObject (B_DC.m_hDC , hbmB);
4041
+
4042
+
4043
+ long count = bmi.bmiHeader .biSizeImage ;
4044
+ long perline = BytesPerLine (iWidth, 24 );
4045
+
4046
+ long i;
4047
+
4048
+ // copy alpha channel into window
4049
+
4050
+ for (i = 0 ; i < count; i += 4 )
4051
+ {
4052
+ pB [i] = pA [i + 3 ];
4053
+ pB [i + 1 ] = pA [i + 3 ];
4054
+ pB [i + 2 ] = pA [i + 3 ];
4055
+ }
4056
+
4057
+
4058
+ // copy result back
4059
+
4060
+ dc.BitBlt (Left, Top, iWidth, iHeight, &B_DC, 0 , 0 , SRCCOPY);
4061
+
4062
+
4063
+ SelectObject (A_DC.m_hDC , hOldAbmp);
4064
+ SelectObject (B_DC.m_hDC , hOldBbmp);
4065
+
4066
+ DeleteObject (hbmA);
4067
+ DeleteObject (hbmB);
4068
+
4069
+ return eOK;
4070
+
4071
+
4072
+ } // end of CMiniWindow::GetImageAlpha
0 commit comments