几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » 程序设计 » vc编程
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-08-19, 08:03 PM   #1
huangyhg
超级版主
 
huangyhg的头像
 
注册日期: 04-03
帖子: 18592
精华: 36
现金: 249466 标准币
资产: 1080358888 标准币
huangyhg 向着好的方向发展
默认 Alpha Blend code (MFC)

void CMyDlg::AlphaBlend(CDC *pDC, double blend)
{
BITMAP bmpX,bmpY;

CBitmap bmp1,bmp2;
bmp2.LoadBitmap(IDB_BITMAP2);
bmp1.LoadBitmap(IDB_BITMAP1);

bmp1.GetBitmap(&bmpX);
UINT* bmpBuffer=(UINT*) GlobalAlloc(GPTR,
bmpX.bmWidthBytes * bmpX.bmHeight);
bmp1.GetBitmapBits(bmpX.bmWidthBytes * bmpX.bmHeight, bmpBuffer);

bmp2.GetBitmap(&bmpY);
UINT* bmpBuffer2=(UINT*) GlobalAlloc(GPTR,
bmpY.bmWidthBytes * bmpY.bmHeight);
bmp2.GetBitmapBits(bmpY.bmWidthBytes * bmpY.bmHeight, bmpBuffer2);

int nSize = bmpY.bmWidth * bmpY.bmHeight;

for (int i = 0; i < nSize; i++)
{
int abR = (int) (GetR(bmpBuffer[i]) * blend +
(1-blend) * GetR(bmpBuffer2[i]));
int abG = (int) (GetG(bmpBuffer[i]) * blend +
(1-blend) * GetG(bmpBuffer2[i]));
int abB = (int) (GetB(bmpBuffer[i]) * blend +
(1-blend) * GetB(bmpBuffer2[i]));

bmpBuffer2[i] = RGB(abB, abG, abR);
}

bmp2.SetBitmapBits(bmpX.bmWidthBytes * bmpX.bmHeight, bmpBuffer2);

CDC memdc;
memdc.CreateCompatibleDC(pDC);
memdc.SelectObject(bmp2);
pDC->BitBlt(10,10,bmpX.bmWidthBytes,
bmpX.bmHeight, &memdc, 0, 0, SRCCOPY);

GlobalFree((HGLOBAL)bmpBuffer);
GlobalFree((HGLOBAL)bmpBuffer2);
memdc.DeleteDC();
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/DonJikn/archiv...02/3858454.aspx
__________________
借用达朗贝尔的名言:前进吧,你会得到信心!
[url="http://www.dimcax.com"]几何尺寸与公差标准[/url]
huangyhg离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
旧 2009-08-19, 08:05 PM   #2
huangyhg
超级版主
 
huangyhg的头像
 
注册日期: 04-03
帖子: 18592
精华: 36
现金: 249466 标准币
资产: 1080358888 标准币
huangyhg 向着好的方向发展
默认 回复: Alpha Blend code (MFC)

类似于AlphaBlend,对24位位图进行透明混合
/*********************************************************************\
* *
* Create24BPPDIBSection(HDC, int, int); *
* *
* Purpose: *
* Creates a 24 bit-per-pixel DIB section with the specified *
* width and height. *
* *
\*********************************************************************/
HBITMAP Create24BPPDIBSection(HDC hDC, int iWidth, int iHeight)
{
BITMAPINFO bmi;
HBITMAP hbm;
LPBYTE pBits;

// Initialize header to 0s.
ZeroMemory(&bmi, sizeof(bmi));

// Fill out the fields you care about.
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = iWidth;
bmi.bmiHeader.biHeight = iHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;

// Create the surface.
hbm = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, (void**)&pBits, NULL, 0);

return(hbm);
}

/*********************************************************************\
* *
* BitmapsCompatible(LPBITMAP, LPBITMAP) *
* *
* Purpose: *
* Compares two bitmap structures to see if the surfaces are *
* the same width, height, and pixel format. *
* *
\*********************************************************************/
BOOL BitmapsCompatible(LPBITMAP lpbm1, LPBITMAP lpbm2)
{
if (lpbm1->bmBitsPixel != lpbm2->bmBitsPixel) return FALSE;
if (lpbm1->bmPlanes != lpbm2->bmPlanes) return FALSE;
if (lpbm1->bmWidth != lpbm2->bmWidth) return FALSE;
if (lpbm1->bmHeight != lpbm2->bmHeight) return FALSE;

return TRUE;
}

/*********************************************************************\
* *
* BOOL BlendImages(HBITMAP, HBITMAP, HBITMAP, DWORD); *
* *
* Purpose: *
* Blends two source images into a destination image *
* using a specified weighting value for the first source *
* image. *
* *
* Notes: *
* All HBITMAP parameters must be 24 bit-per-pixel DIB sections. *
* All HBITMAP parameters must have the same widths and heights. *
* Weighting values must be in the range of 0 .. 255. *
* *
\*********************************************************************/
BOOL BlendImages(HBITMAP hbmSrc1, HBITMAP hbmSrc2, HBITMAP hbmDst, DWORD dwWeight1)
{
BITMAP bmSrc1, bmSrc2, bmDst;
RGBTRIPLE *lprgbSrc1, *lprgbSrc2, *lprgbDst;
DWORD dwWidthBytes, dwWeight2;
int x, y;

// Only values between 0 and 255 are valid.
if (dwWeight1 > 255) return FALSE;

// Get weighting value for second source image.
dwWeight2 = 255-dwWeight1;

// Get information about the surfaces you were passed.
if (!GetObject(hbmSrc1, sizeof(BITMAP), &bmSrc1)) return FALSE;
if (!GetObject(hbmSrc2, sizeof(BITMAP), &bmSrc2)) return FALSE;
if (!GetObject(hbmDst, sizeof(BITMAP), &bmDst)) return FALSE;

// Make sure you have data that meets your requirements.
if (!BitmapsCompatible(&bmSrc1, &bmSrc2)) return FALSE;
if (!BitmapsCompatible(&bmSrc1, &bmDst)) return FALSE;
if (bmSrc1.bmBitsPixel != 24) return FALSE;
if (bmSrc1.bmPlanes != 1) return FALSE;
if (!bmSrc1.bmBits || !bmSrc2.bmBits || !bmDst.bmBits) return FALSE;

dwWidthBytes = bmDst.bmWidthBytes;

// Initialize the surface pointers.
lprgbSrc1 = (RGBTRIPLE*)bmSrc1.bmBits;
lprgbSrc2 = (RGBTRIPLE*)bmSrc2.bmBits;
lprgbDst = (RGBTRIPLE*)bmDst.bmBits;

for (y=0; y<bmDst.bmHeight; y++) {
for (x=0; x<bmDst.bmWidth; x++) {
lprgbDst[x].rgbtRed = (BYTE)((((DWORD)lprgbSrc1[x].rgbtRed * dwWeight1) +
((DWORD)lprgbSrc2[x].rgbtRed * dwWeight2)) >> 8);
lprgbDst[x].rgbtGreen = (BYTE)((((DWORD)lprgbSrc1[x].rgbtGreen * dwWeight1) +
((DWORD)lprgbSrc2[x].rgbtGreen * dwWeight2)) >> 8);
lprgbDst[x].rgbtBlue = (BYTE)((((DWORD)lprgbSrc1[x].rgbtBlue * dwWeight1) +
((DWORD)lprgbSrc2[x].rgbtBlue * dwWeight2)) >> 8);
}

// Move to next scan line.
lprgbSrc1 = (RGBTRIPLE *)((LPBYTE)lprgbSrc1 + dwWidthBytes);
lprgbSrc2 = (RGBTRIPLE *)((LPBYTE)lprgbSrc2 + dwWidthBytes);
lprgbDst = (RGBTRIPLE *)((LPBYTE)lprgbDst + dwWidthBytes);
}

return TRUE;
}

/*********************************************************************\
* *
* BOOL DoAlphaBlend() *
* *
* Purpose: *
* Captures a copy of the source and destination areas and *
* alpha blends them into a memory surface that it displays *
* into the destination area. * * *
* Notes: *
* Takes the same parameters as the AlphaBlend function except *
* that the last parameter is a source weighting value rather *
* than a BLENDFUNCTION structure. *
* *
\*********************************************************************/
BOOL DoAlphaBlend(
HDC hdcDest, // Handle to destination DC.
int nXOriginDest, // X-coord of upper-left corner.
int nYOriginDest, // Y-coord of upper-left corner.
int nWidthDest, // Destination width.
int nHeightDest, // Destination height.
HDC hdcSrc, // Handle to source DC.
int nXOriginSrc, // X-coord of upper-left corner.
int nYOriginSrc, // Y-coord of upper-left corner.
int nWidthSrc, // Source width.
int nHeightSrc, // Source height.
DWORD dwSourceWeight) // Source weighting (between 0 and 255).
{
HDC hdcSrc1 = NULL;
HDC hdcSrc2 = NULL;
HDC hdcDst = NULL;
HBITMAP hbmSrc1 = NULL;
HBITMAP hbmSrc2 = NULL;
HBITMAP hbmDst = NULL;
BOOL bReturn;

// Create surfaces for sources and destination images.
hbmSrc1 = Create24BPPDIBSection(hdcDest, nWidthDest,nHeightDest);
if (!hbmSrc1) goto HANDLEERROR;

hbmSrc2 = Create24BPPDIBSection(hdcDest, nWidthDest,nHeightDest);
if (!hbmSrc2) goto HANDLEERROR;

hbmDst = Create24BPPDIBSection(hdcDest, nWidthDest,nHeightDest);
if (!hbmDst) goto HANDLEERROR;


// Create HDCs to hold our surfaces.
hdcSrc1 = CreateCompatibleDC(hdcDest);
if (!hdcSrc1) goto HANDLEERROR;

hdcSrc2 = CreateCompatibleDC(hdcDest);
if (!hdcSrc2) goto HANDLEERROR;

hdcDst = CreateCompatibleDC(hdcDest);
if (!hdcDst) goto HANDLEERROR;


// Prepare the surfaces for drawing.
SelectObject(hdcSrc1, hbmSrc1);
SelectObject(hdcSrc2, hbmSrc2);
SelectObject(hdcDst, hbmDst);
SetStretchBltMode(hdcSrc1, COLORONCOLOR);
SetStretchBltMode(hdcSrc2, COLORONCOLOR);


// Capture a copy of the source area.
if (!StretchBlt(hdcSrc1, 0,0,nWidthDest,nHeightDest,
hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
SRCCOPY))
goto HANDLEERROR;

// Capture a copy of the destination area.
if (!StretchBlt(hdcSrc2, 0,0,nWidthDest,nHeightDest,
hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
SRCCOPY))
goto HANDLEERROR;


// Blend the two source areas to create the destination image.
bReturn = BlendImages(hbmSrc1, hbmSrc2, hbmDst, dwSourceWeight);


// Clean up objects you do not need any longer.
// You cannot delete an object that's selected into an
// HDC so delete the HDC first.
DeleteDC(hdcSrc1);
DeleteDC(hdcSrc2);
DeleteObject(hbmSrc1);
DeleteObject(hbmSrc2);


// Display the blended (destination) image to the target HDC.
if (bReturn) {
BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
hdcDst, 0,0, SRCCOPY);
}


// Clean up the rest of the objects you created.
DeleteDC(hdcDst);
DeleteObject(hbmDst);

return bReturn;

HANDLEERROR:

if (hdcSrc1) DeleteDC(hdcSrc1);
if (hdcSrc2) DeleteDC(hdcSrc2);
if (hdcDst) DeleteDC(hdcDst);
if (hbmSrc1) DeleteObject(hbmSrc1);
if (hbmSrc2) DeleteObject(hbmSrc2);
if (hbmDst) DeleteObject(hbmDst);

return FALSE;
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/mynamelj/archi...26/4027753.aspx
__________________
借用达朗贝尔的名言:前进吧,你会得到信心!
[url="http://www.dimcax.com"]几何尺寸与公差标准[/url]
huangyhg离线中   回复时引用此帖
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】rendering On Existing Mfc Device Conte yang686526 DirectDWG 0 2009-05-07 02:57 PM
【转帖】no lineweights on bmp-expor yang686526 DirectDWG 0 2009-05-06 06:34 PM
【转帖】nls error yang686526 DirectDWG 0 2009-05-06 06:34 PM
【转帖】asme美国机械工程师标准目录2 huangyhg American standards 0 2009-04-26 02:31 PM
【转帖】dll学习(资料收集) huangyhg vc编程 0 2008-05-17 09:24 PM


所有的时间均为北京时间。 现在的时间是 07:05 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多