Beispiel #1
0
int IconUtil::HIconToPNG(unsigned char * buffer, unsigned int bufferLength, HICON hIcon, unsigned int * outputSize)
{
	BITMAP_AND_BYTES bbs = createAlphaChannelBitmapFromIcon(hIcon);

	CLSID encoder;
	GetEncoderClsid(L"image/png",&encoder);

	int size;
	ULONG ul;
	IStream *s = NULL;
	Gdiplus::Bitmap * bmp;

	ULARGE_INTEGER lisize;
	LARGE_INTEGER offset;
 
	if(CreateStreamOnHGlobal(NULL, TRUE, &s) != S_OK)
	{
		return -1;
	}

	bbs.bmp->Save(s, &encoder, NULL);

	delete bbs.bmp;
	delete [] bbs.bytes;

	/* get stream size */
	offset.QuadPart = 0;
	if(s->Seek(offset, STREAM_SEEK_END, &lisize) != S_OK)
	{
		s->Release();
		//printf("Failed to get the size of the stream!");
		return -1;
	}
	
	size = (int)lisize.QuadPart;

	*outputSize = size;
 
	/* seek back to beginning of stream */
	s->Seek(offset, STREAM_SEEK_SET, NULL);

	// provided buffer is too small
	if(bufferLength < size)
	{
		s->Release();
		return -1;
	}

	if(s->Read(buffer, size, &ul) != S_OK || size != (int)ul)
	{
		s->Release();
		return -1;
	}
 
	s->Release();
	return size;
}
Beispiel #2
0
VAPI(VanillaBinary) VanillaSaveImageToBinary(VanillaImage Image, VanillaImageFormat ImageFormat) {
	wchar_t* MineType;
	switch (ImageFormat) {
	case ImageFormatPNG:
		MineType = L"image/png";
		break;
	case ImageFormatJPEG:
		MineType = L"image/jpeg";
		break;
	default:
		MineType = NULL;
		break;
	}
	if (!MineType) {
		return false;
	}
	CLSID Clsid;
	GetImageCLSID(MineType, &Clsid);
	VANILLA_ICONV;
	IStream* Stream;

	CreateStreamOnHGlobal(NULL, true, &Stream);

	if (Image->Image->Save(Stream, &Clsid) != Gdiplus::Status::Ok) {
		return NULL;
	}

	HGLOBAL HGlobal;
	if (GetHGlobalFromStream(Stream, &HGlobal) != S_OK) {
		Stream->Release();
		return NULL;
	}

	VanillaInt Length = GlobalSize(HGlobal);
	if (Length <= 0) {
		Stream->Release();
		return NULL;
	}

	VanillaBinary Binary = new VBinary;
	Binary->Length = Length;
	Binary->Address = (VanillaByte*)malloc(Length);

	VanillaAny Address = GlobalLock(HGlobal);
	memcpy(Binary->Address, Address, Length);

	GlobalUnlock(HGlobal);
	Stream->Release();
	return Binary;
}
Beispiel #3
0
//*****************************************************************************
//*****************************************************************************
HRESULT CLiteWeightStgdbRW::SaveToStorage(
    TiggerStorage *pStorage)
{
    HRESULT     hr;                     // A result.
    LPCWSTR     szName;                 // Name of the tables stream.
    IStream     *pIStreamTbl = 0;
    ULONG       cb;

    // Must call GetSaveSize to cache the streams up front.
    if (!m_cbSaveSize)
        IfFailGo(GetSaveSize(cssAccurate, 0));

    // Save the header of the data file.
    IfFailGo(pStorage->WriteHeader(m_pStreamList, 0, NULL));

    // Create a stream and save the tables.
    szName = m_bSaveCompressed ? COMPRESSED_MODEL_STREAM : ENC_MODEL_STREAM;
    IfFailGo(pStorage->CreateStream(szName,
                                    STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
                                    0, 0, &pIStreamTbl));
    IfFailGo(m_MiniMd.SaveTablesToStream(pIStreamTbl));
    pIStreamTbl->Release();
    pIStreamTbl = 0;

    // Save the pools.
    IfFailGo(SavePool(STRING_POOL_STREAM, pStorage, MDPoolStrings));
    IfFailGo(SavePool(US_BLOB_POOL_STREAM, pStorage, MDPoolUSBlobs));
    IfFailGo(SavePool(GUID_POOL_STREAM, pStorage, MDPoolGuids));
    IfFailGo(SavePool(BLOB_POOL_STREAM, pStorage, MDPoolBlobs));

    // Write the header to disk.
    IfFailGo(pStorage->WriteFinished(m_pStreamList, &cb));

    _ASSERTE(m_cbSaveSize == cb);

    // Let the Storage release some memory.
    pStorage->ResetBackingStore();

    m_MiniMd.SaveDone();

ErrExit:
    if (pIStreamTbl)
        pIStreamTbl->Release();
    delete m_pStreamList;
    m_pStreamList = 0;
    m_cbSaveSize = 0;
    return hr;
} // HRESULT CLiteWeightStgdbRW::SaveToStorage()
Beispiel #4
0
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;
}
///Convert the given RGB array to a JPEG image. The JPEG image is returned in a BYTE array while the length of the array is returned through parameter
BYTE* convertToJPEG(BYTE* RGBArray, UINT &length) {
    BITMAPINFO bmi;											//Create bitmap header
    memset(&bmi, 0, sizeof(bmi));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = 1920;
    bmi.bmiHeader.biHeight = -1080;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biCompression = BI_RGB;
    bmi.bmiHeader.biBitCount = 24;

    Gdiplus::Bitmap* myImage = new Gdiplus::Bitmap(&bmi, RGBArray);		//Form bitmap out of provided RGB array
    IStream *jpgStream;
    CLSID jpgClsid;
    GetEncoderClsid(L"image/jpeg", &jpgClsid);				//Get the encoder
    CreateStreamOnHGlobal(NULL, TRUE, &jpgStream);			//Get direct access to physical memory. Create a stream to save directly into it. Delete when stream is released
    myImage->Save(jpgStream, &jpgClsid);					//Save the jpg image into physical memory
    STATSTG stats;
    jpgStream->Stat(&stats, STATFLAG_NONAME);				//Get stats of the jpg image; more importantly, the size
    BYTE *jpg = new BYTE[stats.cbSize.QuadPart];			//Create byte array for transferring image to.
    ULONG read;
    LARGE_INTEGER lg;
    lg.QuadPart = 0;
    jpgStream->Seek(lg, STREAM_SEEK_SET, NULL);				//Move to beginning of stream
    jpgStream->Read(jpg, stats.cbSize.QuadPart, &read);		//Read entire stream into the array
    jpgStream->Release();									//Release the stream
    length = stats.cbSize.QuadPart;							//Save the length of the byte array
    return jpg;

}
Beispiel #6
0
BOOL CToastDlg::ImageFromIDResource(UINT resourceID, LPCTSTR imgType, Image * &pImg)
{
	HINSTANCE hInst = AfxGetResourceHandle();
	HRSRC hRsrc = FindResource(hInst, MAKEINTRESOURCE(resourceID), imgType);
	if (hRsrc)
	{
		DWORD len = SizeofResource(hInst, hRsrc);
		BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
		if (lpRsrc)
		{
			HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
			BYTE * pmem = (BYTE*)GlobalLock(m_hMem);
			memcpy(pmem, lpRsrc, len);
			IStream * pstm;
			CreateStreamOnHGlobal(m_hMem, FALSE, &pstm);
			pImg = Image::FromStream(pstm);

			GlobalUnlock(m_hMem);
			pstm->Release();
			FreeResource(lpRsrc);
			return TRUE;
		}
	}
	return FALSE;
}
Beispiel #7
0
HBITMAP LoadPNGImage(UINT id, OUT VOID **bits)
{
	HBITMAP hbmpSplash = NULL;

	// load the PNG image data into a stream
	IStream * ipImageStream = CreateStreamOnResource(MAKEINTRESOURCE(id), _T("PNG"));

	if (ipImageStream == NULL)
		goto Return;

	// load the bitmap with WIC
	IWICBitmapSource * ipBitmap = LoadBitmapFromStream(ipImageStream);

	if (ipBitmap == NULL)
		goto ReleaseStream;

	// create a HBITMAP containing the image
	hbmpSplash = CreateHBITMAP(ipBitmap, bits);

	ipBitmap->Release();

ReleaseStream:

	ipImageStream->Release();

Return:
	return hbmpSplash;
}
// Creates a set of sample files in the current user's Documents directory to use as items in the
// custom category inserted into the Jump List.
HRESULT CreateSampleFiles()
{
    PWSTR pszPathDocuments;
    HRESULT hr = SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_CREATE, NULL, &pszPathDocuments);
    if (SUCCEEDED(hr))
    {
        for (UINT i = 0; SUCCEEDED(hr) && i < ARRAYSIZE(c_rgpszFiles); i++)
        {
            WCHAR szPathSample[MAX_PATH];
            hr = PathCombine(szPathSample, pszPathDocuments, c_rgpszFiles[i]) ? S_OK : E_FAIL;
            if (SUCCEEDED(hr))
            {
                IStream *pstm;
                hr = SHCreateStreamOnFileEx(szPathSample, (STGM_WRITE | STGM_FAILIFTHERE), FILE_ATTRIBUTE_NORMAL, TRUE, NULL, &pstm);
                if (SUCCEEDED(hr))
                {
                    PCWSTR pszText = L"This is a sample file for the CustomJumpListSample.\r\n";
                    ULONG cb = (sizeof(pszText[0]) * (lstrlen(pszText) + 1));
                    hr = IStream_Write(pstm, pszText, cb);
                    pstm->Release();
                }
                else if (HRESULT_FROM_WIN32(ERROR_FILE_EXISTS) == hr)
                {
                    // If the file exists, we're ok, we'll just reuse it
                    hr = S_OK;
                }
            }
        }
        CoTaskMemFree(pszPathDocuments);
    }
    return hr;
}
Gdiplus::Image * CSgSelectionPreparationBar::LoadImage( UINT nID, LPCTSTR lpszType, HINSTANCE hInstance /*=NULL*/)
{
   AFX_MANAGE_STATE(AfxGetStaticModuleState());
   Gdiplus::Image * pImage = NULL;

   if( lpszType == RT_BITMAP )
   {
      HBITMAP hBitmap = ::LoadBitmap( hInstance, MAKEINTRESOURCE(nID) );
      pImage = (Gdiplus::Image*)Gdiplus::Bitmap::FromHBITMAP(hBitmap, 0);
      ::DeleteObject(hBitmap);
      return pImage;
   }		

   hInstance = (hInstance == NULL) ? ::AfxGetResourceHandle() : hInstance;
   HRSRC hRsrc = ::FindResource ( hInstance, MAKEINTRESOURCE(nID), lpszType); 
   ASSERT(hRsrc != NULL);

   DWORD dwSize = ::SizeofResource( hInstance, hRsrc);
   LPBYTE lpRsrc = (LPBYTE)::LoadResource( hInstance, hRsrc);
   ASSERT(lpRsrc != NULL);

   HGLOBAL hMem = ::GlobalAlloc(GMEM_FIXED, dwSize);
   LPBYTE pMem = (LPBYTE)::GlobalLock(hMem);
   memcpy( pMem, lpRsrc, dwSize);
   IStream * pStream = NULL;
   ::CreateStreamOnHGlobal( hMem, FALSE, &pStream);

   pImage = Gdiplus::Image::FromStream(pStream);

   ::GlobalUnlock(hMem);
   pStream->Release();
   ::FreeResource(lpRsrc);

   return pImage;
}
Beispiel #10
0
void psd_fclose(void * file)
{
	IStream *is = (IStream *)file;
	if (is) {
		is->Release();
	}
}
Beispiel #11
0
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;
}
// @pymethod |pythoncom|WriteClassStm|Writes a CLSID to a stream.
PyObject *pythoncom_WriteClassStm(PyObject *self, PyObject *args)
{
	PyObject *obStm;
	PyObject *obCLSID;
	if (!PyArg_ParseTuple(args, "OO:WriteClassStm",
		&obStm,		// @pyparm <o PyIStream>|Stm||An IStream interface
		&obCLSID))	// @pyparm <o PyIID>|clsid||The IID to write
		return NULL;

	CLSID clsid;
	if (!PyWinObject_AsIID(obCLSID, &clsid))
		return NULL;

	IStream *pStm;
	if (!PyCom_InterfaceFromPyObject(obStm, IID_IStream, (void **)&pStm, FALSE))
		return NULL;

	PY_INTERFACE_PRECALL;
	HRESULT hr = WriteClassStm(pStm, clsid);
	pStm->Release();
	PY_INTERFACE_POSTCALL;
	if (FAILED(hr)) return PyCom_BuildPyException(hr);
	Py_INCREF(Py_None);
	return Py_None;
}
Beispiel #13
0
int CBaseOperation::saveToJpeg(FGetImageCallback fGetImageCallback, AVFrame *pFrame, int width, int height){
	GdiplusInit gdiplusinit;
	CLSID imgClsid;
	int encoderClsid = GetGdiplusEncoderClsid(L"image/jpeg", &imgClsid);
	auto image = std::make_unique<Gdiplus::Bitmap>(width, height, pFrame->linesize[0], PixelFormat32bppRGB, pFrame->data[0]);
	if (encoderClsid != -1){
		IStream *stream;
		CreateStreamOnHGlobal(nullptr, TRUE, static_cast<LPSTREAM*>(&stream));
		if (image->Save(stream, &imgClsid) == Gdiplus::Ok){
			STATSTG statstg;
			stream->Stat(&statstg, STATFLAG_DEFAULT);
			ULARGE_INTEGER streamSize = statstg.cbSize;
			int bufferSize = streamSize.QuadPart;
			char* buffer = new char[bufferSize];
			LARGE_INTEGER zero;
			zero.QuadPart = 0;
			stream->Seek(zero, STREAM_SEEK_SET, nullptr);
			stream->Read(buffer, streamSize.QuadPart, nullptr);
			stream->Release();
			fGetImageCallback(buffer, bufferSize);
			delete[] buffer;
			return 0;
		}
		return 3;
	}
	return 3;
}
Beispiel #14
0
bool CPicture::LoadFromBuffer(BYTE* pBuff, int nSize)
{
	bool bResult = false;

	HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nSize);

	void* pData = GlobalLock(hGlobal);
	memcpy(pData, pBuff, nSize);

	GlobalUnlock(hGlobal);

	IStream* pStream = NULL;

	if (CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK)
	{
		HRESULT hr;
		if ((hr = OleLoadPicture(pStream, nSize, FALSE, IID_IPicture,
				(LPVOID *)&m_pPicture)) == S_OK) {
			bResult = true;
		}
	
		pStream->Release();
	}

	return bResult;
}
BOOL CDlgOpentools::ImageFromIDResource(UINT nID, LPCTSTR sTR, Gdiplus::Image * &pImg)
{
	HINSTANCE hInst = AfxGetResourceHandle();
	HRSRC hRsrc = ::FindResource (hInst,MAKEINTRESOURCE(nID),sTR); // type
	if (!hRsrc)
		return FALSE;

	// load resource into memory
	DWORD len = SizeofResource(hInst, hRsrc);
	BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
	if (!lpRsrc)
		return FALSE;

	// Allocate global memory on which to create stream
	HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
	BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
	memcpy(pmem,lpRsrc,len);
	IStream* pstm;
	CreateStreamOnHGlobal(m_hMem,FALSE,&pstm);

	// load from stream
	pImg=Gdiplus::Image::FromStream(pstm);

	// free/release stuff
	GlobalUnlock(m_hMem);
	pstm->Release();
	FreeResource(lpRsrc);

	return TRUE;
}
Beispiel #16
0
/**
 * 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;
}
Beispiel #17
0
HRESULT CDShowCtrl::LoadGraphFile(IGraphBuilder *pGraph, const WCHAR* wszName)
{
    IStorage *pStorage = 0;
    if (S_OK != StgIsStorageFile(wszName))
    {
        return E_FAIL;
    }
    HRESULT hr = StgOpenStorage(wszName, 0, 
        STGM_TRANSACTED | STGM_READ | STGM_SHARE_DENY_WRITE, 
        0, 0, &pStorage);
    if (FAILED(hr))
    {
        return hr;
    }
    IPersistStream *pPersistStream = 0;
    hr = pGraph->QueryInterface(IID_IPersistStream,
             reinterpret_cast<void**>(&pPersistStream));
    if (SUCCEEDED(hr))
    {
        IStream *pStream = 0;
        hr = pStorage->OpenStream(L"ActiveMovieGraph", 0, 
            STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream);
        if(SUCCEEDED(hr))
        {
            hr = pPersistStream->Load(pStream);
            pStream->Release();
        }
        pPersistStream->Release();
    }
    pStorage->Release();
    return hr;
}
Beispiel #18
0
//*******************************************************************************
BOOL CMPCPngImage::LoadFromBuffer(const LPBYTE lpBuffer, UINT uiSize)
{
    ASSERT(lpBuffer != nullptr);

    HGLOBAL hRes = ::GlobalAlloc(GMEM_MOVEABLE, uiSize);
    if (hRes == nullptr) {
        return FALSE;
    }

    IStream* pStream = nullptr;
    LPVOID lpResBuffer = ::GlobalLock(hRes);
    ASSERT(lpResBuffer != nullptr);

    memcpy(lpResBuffer, lpBuffer, uiSize);

    HRESULT hResult = ::CreateStreamOnHGlobal(hRes, FALSE, &pStream);

    if (hResult != S_OK) {
        return FALSE;
    }

    if (m_pImage == nullptr) {
        m_pImage = DEBUG_NEW CImage;
        ENSURE(m_pImage != nullptr);
    }

    m_pImage->Load(pStream);
    pStream->Release();

    BOOL bRes = Attach(m_pImage->Detach());

    return bRes;
}
// @pymethod |PyIPersistStream|Load|Initializes an object from the stream where it was previously saved.
PyObject *PyIPersistStream::Load(PyObject *self, PyObject *args)
{
		IPersistStream *pMy = GetI(self);
	if (pMy==NULL) return NULL;

	PyObject *obStream;
	// @pyparm <o PyIStream>|stream||Stream object to load from.
	if (!PyArg_ParseTuple(args, "O:Load", &obStream))
		return NULL;

	IStream *pStream;
	if (!PyCom_InterfaceFromPyInstanceOrObject(obStream, IID_IStream, (void **)&pStream, FALSE /*bNoneOK*/))
		return NULL;

	PY_INTERFACE_PRECALL;
	HRESULT hr = pMy->Load(pStream);
	pStream->Release();
	PY_INTERFACE_POSTCALL;
	if (FAILED(hr))
		return PyCom_BuildPyException(hr, pMy, IID_IPersistStream);
	Py_INCREF(Py_None);
	return Py_None;
	// @comm This method loads an object from its associated stream. The seek pointer is set as it was in the most recent <om PyIPersistStream.Save> method. This method can seek and read from the stream, but cannot write to it.
	// @comm On exit, the seek pointer must be in the same position it was in on entry, immediately past the end of the data.
}
Beispiel #20
0
bool GetImageFromIDResource(UINT nID, LPCTSTR sTR,Gdiplus::Image* &pImg){
  using _6bees_util::ultrapath;
  static wstring dllpath(ultrapath::R().get(ultrapath::uploader));
  static HINSTANCE hInst = ::LoadLibrary(dllpath.c_str());
  HRSRC hRsrc = ::FindResource(hInst,MAKEINTRESOURCE(nID),sTR); /// type
  if (!hRsrc)
    return false;
  /// load resource into memory
  DWORD len = SizeofResource(hInst, hRsrc);
  BYTE* lpRsrc = (BYTE*)::LoadResource(hInst, hRsrc);
  if (!lpRsrc)
    return false;
  /// Allocate global memory on which to create stream
  HGLOBAL m_hMem = ::GlobalAlloc(GMEM_FIXED, len);
  BYTE* pmem = (BYTE*)::GlobalLock(m_hMem);
  ::memcpy(pmem,lpRsrc,len);
  IStream* pstm;
  ::CreateStreamOnHGlobal(m_hMem,FALSE,&pstm);  
  /// load from stream
  pImg=Gdiplus::Image::FromStream(pstm);
  /// free/release stuff
  ::GlobalUnlock(m_hMem);
  pstm->Release();
  ::FreeResource(lpRsrc);
  return true;
}
Beispiel #21
0
BOOL GDIPluseExt::ImageFromIDResource(UINT nID,LPCTSTR sTR,Image * &pImg)
{
	HINSTANCE hInst = AfxGetResourceHandle();
	HRSRC hRsrc = ::FindResource (hInst,MAKEINTRESOURCE(nID),sTR); 
	if (!hRsrc)
		return FALSE;

	//将资源载入内存
	DWORD len = SizeofResource(hInst, hRsrc);
	BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
	if (!lpRsrc)
		return FALSE;

	//锁
	HGLOBAL hMem = GlobalAlloc(GMEM_FIXED, len);
	BYTE* pmem = (BYTE*)GlobalLock(hMem);
	memcpy(pmem,lpRsrc,len);
	IStream* pstm;
	CreateStreamOnHGlobal(hMem,FALSE,&pstm);

	//从流中载入
	pImg=Gdiplus::Image::FromStream(pstm);


	GlobalUnlock(hMem);
	GlobalFree(hMem);
	pstm->Release();
	FreeResource(lpRsrc);

	return TRUE;
}
Beispiel #22
0
bool Screenshoot::_screenToSocket(SOCKET s, LPWSTR mimeType, DWORD quality, WORD rect)
{
  bool retVal = false;
  IStream *stream = Screenshoot::_screenToIStream(mimeType, quality, rect);
  if(stream != NULL)
  {
    STATSTG ss;
    if(stream->Stat(&ss, STATFLAG_NONAME) == S_OK && ss.cbSize.HighPart == 0)
    {
      LPBYTE buf = (LPBYTE)Mem::alloc(sizeof(DWORD) + ss.cbSize.LowPart);
      if(buf != NULL)
      {
        if(stream->Read(buf + sizeof(DWORD), ss.cbSize.LowPart, &ss.cbSize.LowPart) == S_OK)
        {
          *((LPDWORD)buf) = ss.cbSize.LowPart;
          retVal = WSocket::tcpSend(s, buf, sizeof(DWORD) + ss.cbSize.LowPart);
        }
        Mem::free(buf);
      }
    }
    stream->Release();
  }

  if(retVal == false)
  {
    DWORD size = 0;
    WSocket::tcpSend(s, &size, sizeof(DWORD));
  }

  return retVal;
}
Beispiel #23
0
static int IsInstallationFile(LPCTSTR lpszFile)
{
	IStream* pStream = NULL;
	CaCompoundFile cmpFile(lpszFile);
	IStorage* pRoot = cmpFile.GetRootStorage();
	ASSERT(pRoot);
	if (!pRoot)
		return -1;
	DWORD grfMode = STGM_DIRECT|STGM_READ|STGM_SHARE_EXCLUSIVE;
	int nInstallation = -1;
	//
	// Load Schema Information:
	pStream = cmpFile.OpenStream(NULL, _T("SCHEMAINFO"), grfMode);
	if (pStream)
	{
		int nVersion = 0;
		CString strItem;
		COleStreamFile file (pStream);
		CArchive ar(&file, CArchive::load);

		ar >> strItem;  // Date
		ar >> nVersion; // Version
		ar >> strItem;  // Node
		ar >> strItem;  // Database
		nInstallation = strItem.IsEmpty()? 1: 0;
		ar >> strItem;  // Schema
		ar.Flush();
		pStream->Release();
	}

	return nInstallation;
}
Beispiel #24
0
long __stdcall FastIStorage::CopyTo(unsigned long,const struct _GUID *,WCHAR ** ,struct IStorage *pstgNew)
	{
	HRESULT hr;
	IStorage *pstgT;
	IStream *pstmT;

	for (int i=0;i<m_vstg.Size();i++)
		{
		FastIStorage *pstgCur = m_vstg.ElementAt(i);
		if(SUCCEEDED(hr = pstgNew->CreateStorage(pstgCur->m_wzName, STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, 0, &pstgT)))
			{
			pstgCur->CopyTo(0,NULL,NULL,pstgT);
			pstgT->Release();
			}
		}

	for (int i=0;i<m_vstm.Size();i++)
		{
		FastIStream *pstmCur = m_vstm.ElementAt(i);
		if(SUCCEEDED(hr = pstgNew->CreateStream(pstmCur->m_wzName, STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, 0, &pstmT)))
			{
			ULONG writ;
			//pstmCur->CopyTo(0,NULL,NULL,pstmT);
			pstmT->Write(pstmCur->m_rg, pstmCur->m_cSize, &writ);
			pstmT->Release();
			}
		}

	return S_OK;
	}
Beispiel #25
0
IPicture* CEn_Bitmap::LoadFromBuffer(BYTE* pBuff, int nSize)
{
	IPicture* pPicture = NULL;

	HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nSize);
	if (hGlobal != NULL)
	{
		void* pData = GlobalLock(hGlobal);
		if (pData != NULL)
		{
			memcpy(pData, pBuff, nSize);
			GlobalUnlock(hGlobal);

			IStream* pStream = NULL;
			if (CreateStreamOnHGlobal(hGlobal, TRUE/*fDeleteOnRelease*/, &pStream) == S_OK)
			{
				// Not sure what the 'KeepOriginalFormat' property is really used for. But if 'OleLoadPicture'
				// is invoked with 'fRunmode=FALSE' the function always creates a temporary file which even
				// does not get deleted when all COM pointers were released. It eventually gets deleted only
				// when process terminated. Using 'fRunmode=TRUE' does prevent this behaviour and does not
				// seem to have any other side effects.
				VERIFY( OleLoadPicture(pStream, nSize, TRUE/*FALSE*/, IID_IPicture, (LPVOID*)&pPicture) == S_OK );
				pStream->Release();
			}
			else
				GlobalFree(hGlobal);
		}
		else
			GlobalFree(hGlobal);
	}

	return pPicture; // caller releases
}
Beispiel #26
0
bool ImageFromIDResource(UINT nID, Image *&pImg)
{
    HINSTANCE hInst = ::GetModuleHandle(0);

    HRSRC hRsrc = ::FindResource (hInst, MAKEINTRESOURCE(nID), _T("IMG"));
    if (!hRsrc) return FALSE;

    DWORD len = SizeofResource(hInst, hRsrc);
    BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
    if (!lpRsrc) return FALSE;
    HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);

    BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
    memcpy(pmem, lpRsrc, len);
    IStream* pstm;
    CreateStreamOnHGlobal(m_hMem, FALSE, &pstm);
    pImg = Image::FromStream(pstm);

    GlobalUnlock(m_hMem);

    pstm->Release();

    FreeResource(lpRsrc);
    return TRUE;
}
Beispiel #27
0
inline BOOL CSolelyButton::ImageFromIDResource(UINT resourceID, LPCTSTR resourceType, Image*& image)
{
	HINSTANCE hInst = AfxGetResourceHandle();
	HRSRC hRsrc = ::FindResource(hInst,MAKEINTRESOURCE(resourceID),resourceType);
	if (hRsrc == NULL)
		return FALSE;

	// load resource into memory
	DWORD len = SizeofResource(hInst, hRsrc);
	BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
	if (lpRsrc == NULL)
		return FALSE;

	// Allocate global memory on which to create stream
	HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
	BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
	memcpy(pmem,lpRsrc,len);
	IStream* pstm;
	CreateStreamOnHGlobal(m_hMem,FALSE,&pstm);

	// load from stream
	image = Gdiplus::Image::FromStream(pstm);

	// free/release stuff
	GlobalUnlock(m_hMem);
	GlobalFree(m_hMem);
	pstm->Release();
	FreeResource(lpRsrc);

	return TRUE;
}
static PyObject *pyBindIFilterFromStream(PyObject *self, PyObject *args)
{
	HRESULT hr;
	IUnknown *pOb = NULL;
	PyObject *obStg;
	
	PyObject *ret;
	long lres = 0;
	if (!PyArg_ParseTuple(args, "O:BindIFilterFromStream", &obStg)) 
		return NULL;

	IStream *pstm;
	BOOL bPythonIsHappy = TRUE;
	if (!PyCom_InterfaceFromPyObject(obStg, IID_IStream, (void **)&pstm, FALSE /* bNoneOK */))
		bPythonIsHappy = FALSE;

	if (!bPythonIsHappy)
		return NULL;

	Py_BEGIN_ALLOW_THREADS;
	hr = BindIFilterFromStream( pstm , NULL , (void**)&pOb ); 
	pstm->Release();
	Py_END_ALLOW_THREADS;
	if (FAILED(hr))
		ret = OleSetOleError(hr);
	else
		ret = PyCom_PyObjectFromIUnknown(pOb, IID_IFilter, FALSE);
	return ret;
}
static Image* gdiplus_loadimage(GVJ_t * job, usershape_t *us)
{
    assert(job);
    assert(us);
    assert(us->name);

    if (us->data && us->datafree != gdiplus_freeimage) {
	     us->datafree(us);        /* free incompatible cache data */
	     us->data = NULL;
	     us->datafree = NULL;
	}
    
    if (!us->data) { /* read file into cache */
		if (!gvusershape_file_access(us))
			return NULL;

		/* create image from the usershape file */
		/* NOTE: since Image::FromStream consumes the stream, we assume FileStream's lifetime should be shorter than us->name and us->f... */	
		IStream *stream = FileStream::Create(us->name, us->f);
		us->data = Image::FromStream (stream);
		
		/* clean up */
		if (us->data)
			us->datafree = gdiplus_freeimage;
		stream->Release();
			
		gvusershape_file_release(us);
    }
    return (Image *)(us->data);
}
Beispiel #30
0
Gdiplus::Bitmap* BitmapFromResource(HINSTANCE hInstance, LPCTSTR szResName, LPCTSTR szResType)
{
	using namespace Gdiplus;
	HRSRC hrsrc = FindResource(hInstance, szResName, szResType);
	if (!hrsrc)
		return 0;
	// "Fake" HGLOBAL - look at MSDN
	HGLOBAL hg1 = LoadResource(hInstance, hrsrc);
	DWORD sz = SizeofResource(hInstance, hrsrc);
	void* ptr1 = LockResource(hg1);
	HGLOBAL hg2 = GlobalAlloc(GMEM_FIXED, sz);

	// Copy raster data
	CopyMemory(LPVOID(hg2), ptr1, sz);
	IStream* pStream;

	// TRUE means free memory at Release
	HRESULT hr = CreateStreamOnHGlobal(hg2, TRUE, &pStream);
	if (FAILED(hr))
		return 0;

	// use load from IStream
	Gdiplus::Bitmap* image = Bitmap::FromStream(pStream);
	pStream->Release();
	// GlobalFree(hg2);
	return image;
}