DivMod 函数 DrawAlpha函数

来源:互联网 发布:新闻客户端 网络舆情 编辑:程序博客网 时间:2024/06/05 06:06
DivMod作用计算整数除法的整数商和余数。也就是用参数Dividend除以参数Divisor,得到的整数商存到参数Result中,把余数存到参数Remainder中 定义
DivMod(Dividend: Integer; Divisor: Integer; var Result, Remainder:Integer); 


参数


Dividend:整数,被除数 
Divisor:整数,除数 
Result:整数,商 

Remainder:整数,余数 


今天开始弄剂量显示  模块了,没我想的那么简单,努力的试试吧,准备在主界面与错误显示界面中添加这部分的代码

另外,关于X-RAY的剂量计算方面的知识几乎没有,求解释啊



函数调用

 DrawAlpha(m_pBakBmp, &r, &CPoint(n[i] * BmpLEDNumSize.cx, 0));



函数原型

/************************************************************************************ 函  数:  BOOL CBaseCanvas::DrawAlpha(PMyBitmap pDstBmp, CRect *pRect, CPoint *pPoint)* 参  数:  pDstBmp     绘制的目标位图对象            pRect    绘制目标区域的位置和大小            pPoint      透明信息位图的绘制源坐标* 返回值:  成功时,返回TRUE。* 说  明:  用于透明效果的绘制。************************************************************************************/BOOL CBaseCanvas::DrawAlpha(PMyBitmap pDstBmp, CRect *pRect, CPoint *pPoint){#ifdef DEBUG_TEXT    if (NULL == m_pBmpAlpha)    {        ::MessageBox(NULL, _T("对象m_pBmpAlpha为空"), _T("绘制函数错误!!"), MB_OK);        return FALSE;    }#endif    int l = pRect->left;    int t = pRect->top;    int w = pRect->Width();    int h = pRect->Height();    if(!pDstBmp->AlphaBlend(l, t, w, h, m_pBmpAlpha, pPoint->x, pPoint->y, m_bfAlpha))    {         return FALSE;    }    return TRUE;}
 virtual BOOL AlphaBlend(int x, int y, int nWidth, int nHeight,                           CWceUiGenericBitmap* pSrcBmp, int xSrc, int ySrc, BLENDFUNCTION blendFunction);       和微软的AlphaBlend比较类似,    x, 目标位图的左上角坐标的x    y, 目标位图的左上角坐标的y    nWidth,  目标位图的宽度    nHeight, 目标位图的高度    pSrcBmp, 源位图    xSrc, 源位图的左上角坐标的x    ySrc, 源位图的左上角坐标的y    blendFunction,见微软的AlphaBlend中这个参数的描述    返回TRUE表示成功,FALSE表示失败 

微软的AlphaBlend基本结构:


[cpp] view plaincopy
  1. typedef struct _BLENDFUNCTION {  
  2.   BYTE  BlendOp;  
  3.   BYTE  BlendFlags;  
  4.   BYTE  SourceConstantAlpha;  
  5.   BYTE  AlphaFormat;  
  6. }BLENDFUNCTION, *PBLENDFUNCTION, *LPBLENDFUNCTION;  

This structure controls blending by specifyingthe blending functionsfor source and destination bitmaps.

这里的 the blending functions指的是哪些函数?

我所知道的有一个:

[cpp] view plaincopy
  1. BOOL UpdateLayeredWindow(     
  2.     HWND hwnd,  
  3.     HDC hdcDst,  
  4.     POINT *pptDst,  
  5.     SIZE *psize,  
  6.     HDC hdcSrc,  
  7.     POINT *pptSrc,  
  8.     COLORREF crKey,  
  9.     BLENDFUNCTION *pblend,  
  10.     DWORD dwFlags  
  11.     );  
其中的hdcDst和hdcSrc就是source and destination bitmaps。

——————————————————————————————

BlendOp

Specifies the source blend operation. Currently, the only source and destination blend operationthat has been defined is AC_SRC_OVER. 

目前只有一种混合模式,就是AC_SRC_OVER。

BlendFlags

Must be zero.

SourceConstantAlpha

Specifies an alpha transparency value to be used on the entire source bitmap. The SourceConstantAlpha value is combined with any per-pixel alpha values in the source bitmap. If you set SourceConstantAlpha to 0, it is assumed that your image is transparent. When you only want to use per-pixel alpha values, set the SourceConstantAlpha value to 255 (opaque) .

这个参数设定的是源图像将以什么不透明度叠加在目标图像上。0则透明,255则不透明。
AlphaFormat

This member controls the way the source and destination bitmaps are interpreted. 

AC_SRC_ALPHA:

This flag is set when the bitmap has an Alpha channel (that is, per-pixel alpha). Because this API uses premultiplied alpha, the red, green and blue channel values in the bitmap must be premultiplied with the alpha channel value. For example, if the alpha channel value is x, the red, green and blue channels must be multiplied by x and divided by 0xff before the call.

以上结构体解释完毕,下面是使用事项。

When the AlphaFormat parameter is AC_SRC_ALPHA, the source bitmap must be 32 bpp. If it is not, the AlphaBlend function will fail.

32bpp是真彩色。

When the BlendOp parameter is AC_SRC_OVER , the source bitmap is placed over the destination bitmap based on the alpha values of the source pixels.

If the source bitmap has no per-pixel alpha value (that is, AC_SRC_ALPHA is not set), the SourceConstantAlpha value determines the blend of the source and destination bitmaps, as shown in the following table. Note that SCA is used for SourceConstantAlpha here. Also, SCA is divided by 255 because it has a value that ranges from 0 to 255.

没有alpha通道的话,将按照SourceConstantAlpha 来确定混合效果。混合公式如下:

[cpp] view plaincopy
  1. Dst.Red   = Src.Red   * (SCA/255.0) + Dst.Red   * (1.0 - (SCA/255.0))   
  2. Dst.Green = Src.Green * (SCA/255.0) + Dst.Green * (1.0 - (SCA/255.0))   
  3. Dst.Blue  = Src.Blue  * (SCA/255.0) + Dst.Blue  * (1.0 - (SCA/255.0))   

这里的SCA指的是SourceConstantAlpha。

If the destination bitmap has an alpha channel, then the blend is as follows.

[cpp] view plaincopy
  1. Dst.Alpha = Src.Alpha * (SCA/255.0) + Dst.Alpha * (1.0 - (SCA/255.0))   

If the source bitmap does not use SourceConstantAlpha (that is, it equals 0xFF), the per-pixel alpha determines the blend of the source and destination bitmaps, as shown by the following equations.

如果源图像没有使用SCA,即默认255,叠加效果就只和他的alpha值有关。

[cpp] view plaincopy
  1. Dst.Red   = Src.Red   + (1 - Src.Alpha) * Dst.Red   
  2. Dst.Green = Src.Green + (1 - Src.Alpha) * Dst.Green   
  3. Dst.Blue  = Src.Blue  + (1 - Src.Alpha) * Dst.Blue   

If the destination bitmap has an alpha channel, then the blend is as follows.

[cpp] view plaincopy
  1. Dest.alpha = Src.Alpha + (1 - SrcAlpha) * Dst.Alpha   

If the source has both the SourceConstantAlpha (that is, it is not 0xFF) and per-pixel alpha, the source is pre-multiplied by the SourceConstantAlpha and then the blend is based on the per-pixel alpha. The following equations show this. Note that SourceConstantAlpha is divided by 255 because it has a value that ranges from 0 to 255.

[cpp] view plaincopy
  1. Src.Red   = Src.Red   * SourceConstantAlpha / 255.0;   
  2. Src.Green = Src.Green * SourceConstantAlpha / 255.0;   
  3. Src.Blue  = Src.Blue  * SourceConstantAlpha / 255.0;   
  4. Src.Alpha = Src.Alpha * SourceConstantAlpha / 255.0;   
  5. Dst.Red   = Src.Red   + (1 - Src.Alpha) * Dst.Red   
  6. Dst.Green = Src.Green + (1 - Src.Alpha) * Dst.Green   
  7. Dst.Blue  = Src.Blue  + (1 - Src.Alpha) * Dst.Blue   
  8. Dst.Alpha = Src.Alpha + (1 - Src.Alpha) * Dst.Alpha   





原创粉丝点击