//bmps 中装的是CImage
for(int i = 0; i < bmps[nIndex].GetHeight(); i++){
for(int j = 0; j < bmps[nIndex].GetWidth();j++){
BYTE tp1=(BYTE)bmps[nIndex].GetPixelAddress(i,j);
BYTE tp2=(BYTE)bmps[nIndex+1].GetPixelAddress(i,j);
BYTE tpOut=(BYTE)bitmap.GetPixelAddress(i,j);
_asm{
emms
mov eax,fadetA
movupd xmm3,[eax]
mov ebx,fadetB
movupd xmm4,[ebx]
mov ecx,tp1
movupd xmm5,[ecx]//这里tp1无法读取内存
mov edx,tp2
movupd xmm6,[edx]
pxor xmm7,xmm7
punpcklbw xmm5,xmm7
punpcklbw xmm6,xmm7
punpcklbw xmm3,xmm7
punpcklbw xmm4,xmm7
pmullw xmm5,xmm3
pmullw xmm6,xmm4
psrlw xmm5,8
psrlw xmm6,8
paddw xmm5,xmm6
packuswb xmm5,xmm7
mov edi,tpOut
movsd [edi],xmm5
EMMS;
}
}
}
delete []fadetA;
delete []fadetB;
//tmp = bitmap;
//CDC* pDC;
//pDC = GetWindowDC();
//bitmap.Draw(pDC->m_hDC,0,0);
Ondraw();
}
CImage* CCatchScreenDlg::LoadCImage( UINT nID, LPCTSTR lpszType, HINSTANCE hInstance ) { CImage* pImage = NULL;
hInstance = ( NULL == hInstance ) ? ::AfxGetResourceHandle() : hInstance;
if( RT_BITMAP == lpszType ) { pImage = new CImage(); pImage->LoadFromResource( hInstance, nID ); if ( !pImage->IsNull() ) { return pImage; } else { WriteScreenCatchLog( _T("[CCatchScreenDlg::LoadCImage]CImage::LoadFromResource失败") );
delete pImage;
pImage = NULL;
return NULL;
}
}
CString strLog; HRSRC hRsrc = ::FindResource( hInstance, MAKEINTRESOURCE(nID), lpszType ); ASSERT( hRsrc != NULL ); if ( NULL == hRsrc ) { WriteScreenCatchLog( _T("[CCatchScreenDlg::LoadCImage]::FindResource失败") ); return NULL; }
DWORD dwSize = ::SizeofResource( hInstance, hRsrc); LPBYTE lpRsrc = (LPBYTE)::LoadResource( hInstance, hRsrc); ASSERT( lpRsrc != NULL ); if ( NULL == hRsrc ) { WriteScreenCatchLog( _T("[CCatchScreenDlg::LoadCImage]::LoadResource失败") ); return NULL; }
HGLOBAL hMem = ::GlobalAlloc( GMEM_FIXED, dwSize ); if ( NULL == hMem ) { WriteScreenCatchLog( _T("[CCatchScreenDlg::LoadCImage]::GlobalAlloc失败") );
::FreeResource( lpRsrc );
return NULL;
}
LPBYTE pMem = (LPBYTE)::GlobalLock( hMem ); if ( NULL == pMem ) { WriteScreenCatchLog( _T("[CCatchScreenDlg::LoadCImage]::GlobalLock失败") );
::GlobalUnlock( hMem );
::GlobalFree( hMem );
::FreeResource( lpRsrc );
return NULL;
}
memcpy( pMem, lpRsrc, dwSize ); IStream * pStream = NULL; HRESULT hr = ::CreateStreamOnHGlobal( hMem, FALSE, &pStream ); if ( pStream != NULL && hr == S_OK ) { pImage = new CImage(); HRESULT hrs = pImage->Load( pStream );
pStream->Release();
//释放
::GlobalUnlock( hMem );
::GlobalFree( hMem );
::FreeResource( lpRsrc );
if ( hrs == S_OK )
{
if ( pImage->GetBPP() == 32 )
{
for(int i = 0; i < pImage->GetWidth(); i++)
{
for(int j = 0; j < pImage->GetHeight(); j++)
{
unsigned char* pucColor = reinterpret_cast<unsigned char *>(pImage->GetPixelAddress(i , j));
pucColor[0] = pucColor[0] * pucColor[3] / 255;
pucColor[1] = pucColor[1] * pucColor[3] / 255;
pucColor[2] = pucColor[2] * pucColor[3] / 255;
}
}
}
return pImage;
}
else
{
delete pImage;
pImage = NULL;
return NULL;
}
} else { WriteScreenCatchLog( _T("[CCatchScreenDlg::LoadCImage]::CreateStreamOnHGlobal失败") );
::GlobalUnlock( hMem );
::GlobalFree( hMem );
::FreeResource( lpRsrc );
return NULL;
} }
答案来源于网络
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。