我想将图标保存到VC中的文件中 . 请找到我正在使用的以下代码 . 我可以保存所有正在保存的图标 . 但是当我尝试将抓取图标保存到本地硬盘时,图像周围会出现黑色背景 .
请找到以下代码段 .
在此处输入代码
CURSORINFO ci;
ci.cbSize = sizeof(ci);
GetCursorInfo(&ci);
HICON hico = ci.hCursor;
ICONINFO iconInfo;
GetIconInfo(ci.hCursor, &iconInfo);
BYTE buf[4096];
LONG cbSize = 0;
PICTDESC pd = {sizeof(pd), PICTYPE_ICON};
pd.icon.hicon = ci.hCursor;
CComPtr<IPicture> pPict = NULL;
CComPtr<IStream> pStrm = NULL;
BOOL res = FALSE;
res = SUCCEEDED( ::CreateStreamOnHGlobal(NULL, TRUE, &pStrm) );
res = SUCCEEDED( ::OleCreatePictureIndirect(&pd, IID_IPicture, FALSE, (void**)&pPict) );
res = SUCCEEDED( pPict->SaveAsFile( pStrm, TRUE, &cbSize ) );
if( res )
{
// rewind stream to the beginning
LARGE_INTEGER li = {0};
pStrm->Seek(li, STREAM_SEEK_SET, NULL);
// write to file
HANDLE hFile = ::CreateFile("E:\\abc.jpeg", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
if( INVALID_HANDLE_VALUE != hFile )
{
DWORD dwWritten = 0, dwRead = 0, dwDone = 0;
while( dwDone < cbSize )
{
if( SUCCEEDED(pStrm->Read(buf, sizeof(buf), &dwRead)) )
{
::WriteFile(hFile, buf, dwRead, &dwWritten, NULL);
if( dwWritten != dwRead )
break;
dwDone += dwRead;
}
else
break;
}
_ASSERTE(dwDone == cbSize);
::CloseHandle(hFile);
}
}
请找到下面的图标 . enter image description here
这只发生在gmail中的手ICON . 请找到下面的图片 . enter image description here
提前谢谢你的帮助 .