本文整理汇总了C++中IPicture::get_Handle方法的典型用法代码示例。如果您正苦于以下问题:C++ IPicture::get_Handle方法的具体用法?C++ IPicture::get_Handle怎么用?C++ IPicture::get_Handle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPicture
的用法示例。
在下文中一共展示了IPicture::get_Handle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _LoadAnImage
HBITMAP UIIMEdit::_LoadAnImage(IN CString filePath)
{
HANDLE hFile = CreateFile(filePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); //从指定的路径szImagePath中读取文件句柄
DWORD dwFileSize = GetFileSize(hFile, NULL); //获得图片文件的大小,用来分配全局内存
HGLOBAL hImageMemory = GlobalAlloc(GMEM_MOVEABLE, dwFileSize); //给图片分配全局内存
void *pImageMemory = GlobalLock(hImageMemory); //锁定内存
DWORD dwReadedSize; //保存实际读取的文件大小
ReadFile(hFile, pImageMemory, dwFileSize, &dwReadedSize, NULL); //读取图片到全局内存当中
GlobalUnlock(hImageMemory); //解锁内存
CloseHandle(hFile); //关闭文件句柄
HRESULT hr = NULL;
IStream *pIStream = NULL;//创建一个IStream接口指针,用来保存图片流
IPicture *pIPicture = NULL;//创建一个IPicture接口指针,表示图片对象
hr = CreateStreamOnHGlobal(hImageMemory, false, &pIStream); //用全局内存初使化IStream接口指针
ASSERT(SUCCEEDED(hr));
hr = OleLoadPicture(pIStream, 0, false, IID_IPicture, (LPVOID*)&(pIPicture));//用OleLoadPicture获得IPicture接口指针
ASSERT(SUCCEEDED(hr));
HBITMAP hB = NULL;
pIPicture->get_Handle((unsigned int*)&hB);
// Copy the image. Necessary, because upon p's release,
// the handle is destroyed.
HBITMAP hBB = (HBITMAP)CopyImage(hB, IMAGE_BITMAP, 0, 0,
LR_COPYRETURNORG);
GlobalFree(hImageMemory); //释放全局内存
pIStream->Release(); //释放pIStream
pIPicture->Release(); //释放pIPictur
return hBB;
}
示例2: LoadImageBitmap
HBITMAP Timeout::LoadImageBitmap(HGLOBAL hgbl, DWORD size)
{
HBITMAP hbmp = NULL;
CoInitialize(NULL);
IStream* stream;
HRESULT hr = CreateStreamOnHGlobal(hgbl, FALSE, &stream);
if(SUCCEEDED(hr) && stream) {
ULARGE_INTEGER ul;
ul.LowPart = size;
ul.HighPart = 0;
stream->SetSize(ul);
IPicture* picture;
// Load picture from stream
hr = OleLoadPicture(stream, 0, 0, IID_IPicture, (void**)&picture);
if(SUCCEEDED(hr) && picture) {
// Copy picture to a bitmap resource
HBITMAP hsrc;
picture->get_Handle((OLE_HANDLE *)&hsrc);
hbmp = (HBITMAP)CopyImage(hsrc, IMAGE_BITMAP, 0, 0, 0);
picture->Release();
}
stream->Release();
}
CoUninitialize();
return hbmp;
}
示例3: Decode
/**
* Load a GIF image.
* This will replace the currently-loaded image.
* Animated GIFs are not yet supported -- only the first frame of an
* animated GIF will be loaded.
* @param pGifStream The GIF data buffer (may not be NULL).
* @param pStreamLen The length of the buffer.
* @return @c true if the load succeeded, @c false otherwise (current
* image will still be cleared).
*/
bool GifDecoder::Decode(const unsigned char *pGifStream, int pStreamLen)
{
// Delete current image.
Clean();
bool retv = false;
HGLOBAL buf = GlobalAlloc(GPTR, pStreamLen);
memcpy((void*)buf, pGifStream, pStreamLen);
IStream *stream = NULL;
IPicture *pic = NULL;
// We currently don't support animated GIFs, so set big delay for
// the first frame.
mDelay[0] = 3600000;
// Use OleLoadPicture() to convert the GIF stream to an HBITMAP.
if (SUCCEEDED(CreateStreamOnHGlobal(buf, false, &stream))) {
if (SUCCEEDED(OleLoadPicture(stream, 0, false, IID_IPicture, (void**)&pic))) {
HBITMAP hb = NULL;
pic->get_Handle((OLE_HANDLE*)&hb);
mBitmap[0] = (HBITMAP)CopyImage(hb, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
retv = true;
}
}
if (pic != NULL) pic->Release();
if (stream != NULL) stream->Release();
GlobalFree(buf);
return retv;
}
示例4: LoadAnImage
// Function LoadAnImage: accepts a file name and returns a HBITMAP.
// On error, it returns 0.
HBITMAP LoadAnImage(const char* FileName)
{
// Use IPicture stuff to use JPG / GIF files
IPicture* p;
IStream* s;
HGLOBAL hG;
void* pp;
FILE* fp;
// Read file into memory
fp = fopen(FileName, "rb");
if (!fp)
{
return NULL;
}
fseek(fp,0,SEEK_END);
int fs = ftell(fp);
fseek(fp,0,SEEK_SET);
hG = GlobalAlloc(GPTR,fs);
if(!hG)
{
fclose(fp);
return NULL;
}
pp = (void*)hG;
fread(pp,1,fs,fp);
fclose(fp);
// Create an IStream so IPicture can
CreateStreamOnHGlobal(hG, false, &s);
if(!s)
{
GlobalFree(hG);
return NULL;
}
OleLoadPicture(s,0,false,IID_IPicture,(void**)&p);
if(!p)
{
s->Release();
GlobalFree(hG);
return NULL;
}
s->Release();
GlobalFree(hG);
HBITMAP hB = 0;
p->get_Handle((unsigned int*)&hB);
// Copy the image. Necessary, because upon p's release,
// the handle is destroyed.
HBITMAP hBB = (HBITMAP)CopyImage(hB, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
p->Release();
return hBB;
}
示例5: GDIconvertGraphic
//
// Entry point for conversion
//
UT_Error IE_ImpGraphic_Win32Native::_convertGraphic(UT_ByteBuf * pBB, std::string& mimetype)
{
IPicture* pPicture = NULL;
IStream* stream;
HGLOBAL hG;
HBITMAP hBitmap;
OLE_HANDLE* hB;
PBITMAPINFO bi;
UT_ByteBuf bBufBMP;
UT_Error err;
/* If the system has GDI+, use it*/
if (isGDIPlusAvailable())
{
m_pBB = new UT_ByteBuf();
return GDIconvertGraphic(pBB, m_pBB, mimetype);
}
// the code below always writes out PNG's for now; we could update it to support
// native JPEG images as well, or just delete it and always use GDI+.
mimetype = "image/png";
// We need to store the incoming bytebuffer in a Windows global heap
size_t nBlockLen = pBB->getLength();
hG = GlobalAlloc(GPTR, nBlockLen);
if (!hG)
return UT_IE_NOMEMORY;
CopyMemory(hG, pBB->getPointer(0), nBlockLen);
// Create a stream from heap
HRESULT hr = CreateStreamOnHGlobal(hG,false,&stream);
if (!SUCCEEDED(hr) || !stream)
{
GlobalFree(hG);
return UT_IE_NOMEMORY;
}
hr = OleLoadPicture(stream,0,false,IID_IPicture,(void**)&pPicture);
stream->Release();
GlobalFree(hG);
if (!SUCCEEDED(hr) || !pPicture)
{
return UT_IE_UNKNOWNTYPE;
}
pPicture->get_Handle((unsigned int*)&hB);
hBitmap = (HBITMAP)CopyImage(hB,IMAGE_BITMAP,0,0,LR_COPYRETURNORG);
HWND hWnd = GetDesktopWindow();
// Create a BMP file from a BITMAP
bi = CreateBitmapInfoStruct(hBitmap);
CreateBMPFile(hWnd, bBufBMP, bi, hBitmap, GetDC(hWnd));
LocalFree ((HLOCAL)bi);
InitializePrivateClassData();
/* Read Header Data */
err = Read_BMP_Header(&bBufBMP);
/*
It's not a bitmap, then we have to rendered it into a device
context and get a bitmap from there. Case wmf graphics
*/
if (err)
{
if (err!=UT_IE_BOGUSDOCUMENT)
{
pPicture->Release();
return err;
}
long nWidth = 0;
long nHeight = 0;
long nScaleToWidth= 500;
long nScaleToHeight= 500;
RECT rc, rect;
BYTE *imagedata;
HBITMAP hBit;
HBITMAP hOld;
BITMAPINFO bmi;
HDC hWndDC = GetDC(hWnd);
HDC hMemDC = CreateCompatibleDC(hWndDC);
HBRUSH hBrush = (HBRUSH)GetCurrentObject(hMemDC, OBJ_BRUSH);
pPicture->get_Width (&nWidth);
pPicture->get_Height(&nHeight);
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = nScaleToWidth;
bmi.bmiHeader.biHeight = nScaleToHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24; // as we want true-color
//.........这里部分代码省略.........