//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;
}
}