本文整理汇总了C++中IPicture类的典型用法代码示例。如果您正苦于以下问题:C++ IPicture类的具体用法?C++ IPicture怎么用?C++ IPicture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPicture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CoInitialize
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;
}
示例2: CreateFile
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;
}
示例3: ASSERT
BOOL CEnBitmap::LoadImage(LPCTSTR szImagePath, COLORREF crBack)
{
ASSERT(m_hObject == NULL); // only attach once, detach on destroy
if (m_hObject != NULL)
return FALSE;
BOOL bResult = FALSE;
CFile cFile;
CFileException e;
if (cFile.Open(szImagePath, CFile::modeRead | CFile::typeBinary | CFile::shareDenyWrite, &e))
{
int nSize = static_cast<int>(cFile.GetLength());
BYTE* pBuff = new BYTE[nSize];
if (cFile.Read(pBuff, nSize) > 0)
{
IPicture* pPicture = LoadFromBuffer(pBuff, nSize);
if (pPicture)
{
bResult = Attach(pPicture, crBack);
pPicture->Release();
}
}
delete[] pBuff;
}
return bResult;
}
示例4: Clean
/**
* 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;
}
示例5: drawJPEG
//将jpg数据显示到界面
DWORD WINAPI drawJPEG(LPVOID param)
{
CLiveview *dlg = (CLiveview *)param;
dlg->fetching = true;
while (dlg->fetching)
{
if (dlg->mJpegQueue.size() == 0)
{
continue;
}
IPicture *pPic = getPicFromHGlobal(dlg->mJpegQueue.front());
dlg->mJpegQueue.pop();
if (pPic == NULL)
break;
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
double fX, fY;
CRect rect;
GetClientRect(dlg->m_Liveview.m_hWnd, rect);
fX = rect.Width();
fY = rect.Height();
HDC *pDC = &dlg->m_Liveview.GetDC()->m_hDC;
pPic->Render(*pDC, 0, 0, (DWORD)fX, (DWORD)fY, 0, hmHeight, hmWidth, -hmHeight, NULL);
pPic->Release();
}
dlg->fetching = false;
dlg->FreshUI();
return -1;
}
示例6: PictureFromStream
PicturePtr Picture::FromResource(HWND hwnd,
HINSTANCE instance,
const char *type,
const char *name)
{
PicturePtr result;
if (IStream *stream = StreamFromResource(instance, type, name)) {
IPicture *pic = PictureFromStream(stream);
stream->Release();
if (pic) {
if (HDC hdc = GetDC(hwnd)) {
int width = MakeWidth(hdc, pic);
int height = MakeHeight(hdc, pic);
ReleaseDC(hwnd, hdc);
if (width && height)
result.reset(new Picture(pic, width, height));
}
if (!result)
pic->Release();
}
}
return result;
}
示例7: GetFileType
HBITMAP CEnBitmap::LoadImageFile(LPCTSTR szImagePath, COLORREF crBack)
{
int nType = GetFileType(szImagePath);
//TRACE("Load(%ws)\n", szImagePath);
switch (nType)
{
// i suspect it is more efficient to load
// bmps this way since it avoids creating device contexts etc that the
// IPicture methods requires. that method however is still valuable
// since it handles other image types and transparency
case FT_BMP:
{
HBITMAP bmp=(HBITMAP)::LoadImage(NULL, szImagePath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
BITMAP bi;
::GetObject(bmp, sizeof( BITMAP ), &bi);
BYTE bpp = bi.bmBitsPixel >> 3;
if(bpp==4){
BYTE* pBits = new BYTE[ bi.bmWidth * bi.bmHeight * bpp ];
int p = ::GetBitmapBits( bmp, bi.bmWidth * bi.bmHeight * bpp, pBits);
for (int y=0; y<bi.bmHeight; ++y)
{
BYTE *pPixel= (BYTE *) pBits + bi.bmWidth * 4 * y;
for (int x=0; x<bi.bmWidth ; ++x)
{
pPixel[0]= pPixel[0]*pPixel[3]/255;
pPixel[1]= pPixel[1]*pPixel[3]/255;
pPixel[2]= pPixel[2]*pPixel[3]/255;
pPixel+= 4;
}
}
::SetBitmapBits(bmp, bi.bmWidth*bi.bmHeight*bpp, pBits);
delete pBits;
}
return bmp;
}
case FT_UNKNOWN:
return NULL;
default: // all the rest
{
USES_CONVERSION;
IPicture* pPicture = NULL;
HBITMAP hbm = NULL;
HRESULT hr = OleLoadPicturePath(T2OLE((LPTSTR)szImagePath), NULL, 0, crBack, IID_IPicture, (LPVOID *)&pPicture);
if (pPicture)
{
hbm = ExtractBitmap(pPicture, crBack);
pPicture->Release();
}
return hbm;
}
}
return NULL; // can't get here
}
示例8: 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;
}
示例9: ASSERT
BOOL CEn_Bitmap::LoadImage(LPCTSTR szImagePath, COLORREF crBack)
{
ASSERT(m_hObject == NULL); // only attach once, detach on destroy
if (m_hObject != NULL)
return FALSE;
// If GDI+ is available, use that API because it supports more file formats and images with alpha channels.
// That DLL is installed with WinXP is available as redistributable from Microsoft for Win98+. As this DLL
// may not be available on some OS but we have to link statically to it, we have to take some special care.
//
// NOTE: Do *NOT* forget to specify /DELAYLOAD:gdiplus.dll as link parameter.
static int _bGdiPlusInstalled = -1;
if (_bGdiPlusInstalled == -1)
{
_bGdiPlusInstalled = 0;
HMODULE hLib = LoadLibrary(_T("gdiplus.dll"));
if (hLib != NULL)
{
_bGdiPlusInstalled = GetProcAddress(hLib, "GdiplusStartup") != NULL;
FreeLibrary(hLib);
}
}
if (_bGdiPlusInstalled > 0)
{
CImage img;
if (SUCCEEDED(img.Load(szImagePath)))
{
CBitmap::Attach(img.Detach());
return TRUE;
}
}
BOOL bResult = FALSE;
CFile cFile;
CFileException e;
if (cFile.Open(szImagePath, CFile::modeRead | CFile::typeBinary | CFile::shareDenyWrite, &e))
{
int nSize = (int)cFile.GetLength();
BYTE* pBuff = new BYTE[nSize];
if (cFile.Read(pBuff, nSize) > 0)
{
IPicture* pPicture = LoadFromBuffer(pBuff, nSize);
if (pPicture)
{
bResult = Attach(pPicture, crBack);
pPicture->Release();
}
}
delete [] pBuff;
}
return bResult;
}
示例10: fopen
//拍摄照片按钮
void CLiveview::OnBnClickedBtnpic()
{
Document d;
//发送拍照请求
d = indevice->actTakePicture();
if (indevice->isJsonOk(d))
{
//请求成功就解析照片地址 继续获取
CString pictureurl = d["result"].GetArray()[0].GetArray()[0].GetString();
ULONG size = 0;
PUCHAR picture = HttpClient::getData(pictureurl, size);
if (size <= 0)
{
return;
}
//将图片数据存储为文件
FILE *file = fopen("d:\\picture.jpg", "wb");
if (file)
{
fwrite(picture, size, 1, file);
fclose(file);
}
//将获取的数据解码为照片并显示
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, size);
LPVOID pData = GlobalLock(hGlobal);
memcpy(pData, picture, size);
GlobalUnlock(hGlobal);
delete[] picture;
IPicture *pPic = getPicFromHGlobal(hGlobal);
if (pPic == NULL)
return;
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
double fX, fY;
CRect rect;
mPic.GetWindowRect(&rect);
fX = rect.Width();
fY = rect.Height();
HDC *pDC = &mPic.GetDC()->m_hDC;
pPic->Render(*pDC, 0, 0, (DWORD)fX, (DWORD)fY, 0, hmHeight, hmWidth, -hmHeight, NULL);
pPic->Release();
}
}
示例11: ASSERT
BOOL CEnBitmap::LoadImage(LPCTSTR szImagePath, COLORREF crBack)
{
ASSERT(m_hObject == NULL); // only attach once, detach on destroy
if (m_hObject != NULL)
return FALSE;
// If GDI+ is available, use that API because it supports more file formats and images with alpha channels.
// That DLL is installed with WinXP is available as redistributable from Microsoft for Win98+. As this DLL
// may not be available on some OS but we have to link statically to it, we have to take some special care.
//
extern bool g_bGdiPlusInstalled;
if (g_bGdiPlusInstalled)
{
CImage img;
if (SUCCEEDED(img.Load(szImagePath)))
{
CBitmap::Attach(img.Detach());
return TRUE;
}
}
BOOL bResult = FALSE;
CFile cFile;
CFileException e;
if (cFile.Open(szImagePath, CFile::modeRead | CFile::typeBinary | CFile::shareDenyWrite, &e))
{
int nSize = (int)cFile.GetLength();
BYTE* pBuff = new BYTE[nSize];
if (cFile.Read(pBuff, nSize) > 0)
{
IPicture* pPicture = LoadFromBuffer(pBuff, nSize);
if (pPicture)
{
bResult = Attach(pPicture, crBack);
pPicture->Release();
}
}
delete [] pBuff;
}
return bResult;
}
示例12: CreateFile
bool CLotteryDlg::_loadPic(CString strFullPath, PicInfo* picInfo)
{
try
{
HANDLE hFile = CreateFile(strFullPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return false;
DWORD dwFileSize = GetFileSize(hFile, NULL);
if (-1 == dwFileSize)
return false;
picInfo->_hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
if (picInfo->_hGlobal == NULL)
return false;
void * pImageMemory = GlobalLock(picInfo->_hGlobal);
DWORD dwReadedSize;//保存实际读取的文件的大小
ReadFile(hFile, pImageMemory, dwFileSize, &dwReadedSize, NULL);
GlobalUnlock(picInfo->_hGlobal);
CloseHandle(hFile);
IStream* pIStream;//创建一个ISTream接口指针,保存图片流
IPicture* pIPicture;//创建一个IPicture接口指针,表示图片对象
if (S_OK != CreateStreamOnHGlobal(picInfo->_hGlobal, false, &pIStream))//用全局内存初始化IStream接口指针
return false;
if (S_OK != OleLoadPicture(pIStream, 0, false, IID_IPicture, (LPVOID*)&(pIPicture)))//用OleLoadPicture获得IPicture接口指针
{
::GlobalFree(picInfo->_hGlobal);
pIStream->Release();
return false;
}
//得到IPicture COM接口对象后,就可以进行获得图片信息,显示图片等操作
pIPicture->get_Width(&picInfo->_cx);
pIPicture->get_Height(&picInfo->_cy);
picInfo->_iStream = pIStream;
picInfo->_iPic = pIPicture;
picInfo->_x = picInfo->_y = 0;
picInfo->_strFilePath = strFullPath;
}
catch (...)
{
return false;
}
return true;
}
示例13: GlobalAlloc
HRESULT CPicStatic::ShowJpeg(LPVOID picData,DWORD dwFileSize,int x, int y,CDC *pDC)
{
IStream *pStm;
IPicture *pPic;
BOOL bResult;
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
LPVOID pvData = NULL;
if (hGlobal == NULL)
return false;
pvData = GlobalLock(hGlobal);
if ( pvData == NULL)
return false;
memcpy(pvData,picData,dwFileSize);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
bResult=OleLoadPicture(pStm,dwFileSize,TRUE,IID_IPicture,(LPVOID*)&pPic);
if(FAILED(bResult))
{
// CloseHandle(hFile);
return false;
}
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
//将图形输出到屏幕上(有点像BitBlt)
bResult=pPic->Render(pDC->m_hDC,0,0,x,y,0,hmHeight,hmWidth,-hmHeight,NULL);
// CloseHandle(hFile);
pStm->Release();
pPic->Release();
if (SUCCEEDED(bResult))
{
return S_OK;
}
else
{
return E_FAIL;
}
}
示例14: NewGUI_SaveIcon
std::vector<BYTE> NewGUI_SaveIcon(HICON hIcon)
{
std::vector<BYTE> v;
if(hIcon == NULL) { ASSERT(FALSE); return v; }
IStream* pStream = NULL;
if(FAILED(CreateStreamOnHGlobal(NULL, TRUE, &pStream))) { ASSERT(FALSE); return v; }
if(pStream == NULL) { ASSERT(FALSE); return v; }
PICTDESC pd;
ZeroMemory(&pd, sizeof(PICTDESC));
pd.cbSizeofstruct = sizeof(PICTDESC);
pd.picType = PICTYPE_ICON;
pd.icon.hicon = hIcon;
IPicture* pPic = NULL;
LONG lSize = 0;
bool bPic = SUCCEEDED(OleCreatePictureIndirect(&pd, IID_IPicture,
FALSE, (LPVOID *)&pPic));
bPic &= (pPic != NULL);
if(bPic)
{
if(SUCCEEDED(pPic->SaveAsFile(pStream, TRUE, &lSize)))
{
LARGE_INTEGER liMove;
ZeroMemory(&liMove, sizeof(LARGE_INTEGER));
VERIFY(SUCCEEDED(pStream->Seek(liMove, STREAM_SEEK_SET, NULL)));
v.resize(static_cast<size_t>(lSize));
ULONG cbRead = 0;
VERIFY(SUCCEEDED(pStream->Read(&v[0], static_cast<ULONG>(
lSize), &cbRead)));
if(cbRead == static_cast<ULONG>(lSize)) { } // Success
else { ASSERT(FALSE); v.clear(); }
}
pPic->Release();
}
pStream->Release();
return v;
}
示例15: memcpy
void CCommon::DrawFaceImageMin(CStatic *m_picBox,unsigned char *image,unsigned long int size)
{
CRect rect;
m_picBox->GetClientRect(&rect);//获得pictrue控件所在的举行区域
CDC *pDC=m_picBox->GetDC();//获得pictrue控件的DC
IPicture *pPic;//定义显示图片的接口(可显示jpg格式图片)
HGLOBAL hGlobal=GlobalAlloc(GMEM_MOVEABLE,size);//分配内存空间
void *pData=GlobalLock(hGlobal);//定义图象数据指针
memcpy(pData,image,size);
GlobalUnlock(hGlobal);//释放内存空间
IStream *pStream=NULL;//定义数据流指针
//创建数据流
if(CreateStreamOnHGlobal(hGlobal,TRUE,&pStream)==S_OK)
{
//装载图象文件
if(SUCCEEDED(OleLoadPicture(pStream,size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{
OLE_XSIZE_HIMETRIC hmWidth;
OLE_XSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);//获得图象真实宽度
pPic->get_Height(&hmHeight);//获得图象真实高度
//在控件上显示图片
pPic->Render(*pDC,4,4,rect.Width()-8,rect.Height()-8,0,hmHeight,hmWidth,-hmHeight,NULL);
pPic->Release();
pStream->Release();//释放数据流
}
}
if(hGlobal)
{
GlobalFree(hGlobal);
hGlobal = NULL;
}
m_picBox-> ReleaseDC(pDC);
}