|
I have a main program that includes some images and the code provided works excellent for that.
The problem is that my program has the capability to get images from add on DLLs.
I have tried passing in the current instance of the DLL.
I have tried using AfxSetResourceHandle.
Nothing I do will display an image from my DLL.
1813 == GetLastError(), can't find resource in image file.
The main difference between yours and mine is that mine is a dialog based app.
The app is MFC and the DLLs are not.
Also I want to apply text to the image after it is displayed but the two locations that I have tried this tactic have been unfruitful (OnPaint,OnEraseBkgnd).
Any help would be great
Anonymous
|
|
|
|
|
cannot show the tiff picture................
|
|
|
|
|
I had an Active X control which receive the jpeg data from remote sever with Winsock, and copy the jpeg data into a byte buffer, then load data from buffer into a CPictureHolderEx(which is derived from CPictureHolder)object, so in control's onDraw method, this pictureholder object will render the jpeg picture and display it in a web browser.
the code to loadfrom buffer:
bool CPictureHolderEx::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_pPict)) == S_OK)
bResult = true;
pStream->Release();
GlobalFree( hGlobal);
}
return bResult;
}
Control's onDraw method:
void CDvsCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
int size;
SOCKET sock;
BYTE buffer[20000];
BYTE temp[20000];
sock=ConnectSock(); //connect winsock with remote server
while(CONNECTED){
size=PlayVideo(sock, buffer); //receive jpeg binary data
// and load data into byte buffer.
m_pic.LoadFromBuffer(buffer, size);
m_pic.Render(pdc, rcBounds, rcBounds);
memcpy(buffer,temp,20000);
}
closesocket(sock);
}
This control blocked the browser from doing anything else and crashed after running a little while.
Could someone tell me what's wrong with this control?
Thanks a lot!
|
|
|
|
|
I couldn't open any PNG file. Any hint?
|
|
|
|
|
If I'm not mistaken, PNG support was added in Microsoft Internet Explorer version 5, and the IPicture interface is part of MSIE. If you are running an older version of MSIE than 5 (or Windows than 2000/XP), you might need to upgrade in order to get PNG support.
Also, in a typical Windows app, there will be a number of #defines telling the compiler what Windows version-specific features are allowed, for example:
<br />
#ifndef WINVER // Allow use of features specific to Windows 98 and Windows 2000 or later.<br />
#define WINVER 0x0500<br />
#endif<br />
<br />
#ifndef _WIN32_WINNT // Allow use of features specific to Windows 98 and Windows 2000 or later.<br />
#define _WIN32_WINNT 0x0500 <br />
#endif <br />
<br />
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.<br />
#define _WIN32_WINDOWS 0x0410<br />
#endif<br />
<br />
#ifndef _WIN32_IE // Allow use of features specific to IE 5.0 or later.<br />
#define _WIN32_IE 0x0500 <br />
#endif<br />
Other than that, I'm not sure what could be wrong. I hope this helps.
[ PlanetCPP ][ home of the n00blist ]
|
|
|
|
|
yes,I compiled under win2000 and ie6
but still fail in
OleLoadPicture(pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&m_pIPicture))
so png not displayed???
How can i do?
|
|
|
|
|
Hello,
I'm using CPicture in a MFC App. When I'm loading the first Image with
m_cPicture.Load("C:\\PrevPic.jpg");
all works fine, but when I try it again, there pops up an unhandled exception in the UnLoad() funktion just when the computer wants to
execute
pPicture->Release();
What can I do there?
cp
|
|
|
|
|
Hello,
Have you the code of Paint program or near similar the Paint Program?
Could you sent to me?
My address: vnanbinh@yahoo.com
Thanks a lot of
|
|
|
|
|
I am looking for a add-in class to display Animated Gif.
Thank's a lot
|
|
|
|
|
I attempt to display a damaged jpg file, the result is that program is dead.and OleLoadPicture(...) is can't work.it don't return S_OK, either others, how I can avoid my program isnot dead????
|
|
|
|
|
i have the same question! it is a bug!there someone said that should setup the win2000 sp4(because i use windows2000),but after i did this, i found that the question is also there! do you have a good way?
good luck thanks!
|
|
|
|
|
As usual, there is a problem. I keep getting a linker error: LINK : fatal error LNK1104: cannot open file "nafxcwd.lib". THis file doesnt exist anywhere on my hard drive or either of the 3 CDs that came with VC++6.0. Anybody have any ideas?
|
|
|
|
|
And, as usual, the problem was caused by not reading documentation. nafxcwd.lib is the debug, static link, non-Unicode version of the MFC library. There are many options you can pursue. You can try to do a static link release build which will require nafxcw.lib or you can try a dynamic link build, debug or release.
Incidentally, the project is compiling but it is not linking. Those are two different things.
|
|
|
|
|
Hello Anonymous. Can you be a little more specific about what documentation i should be reading? I tried what you said and it still wont link. Thanks for your help.
|
|
|
|
|
When drawing a animated gif, only the first frame is drawn. How to draw
animated gifs?.
The code works great for regular gifs!.
Thanks
Srinivas.
|
|
|
|
|
I am having the same problem here. Does anyone have any idea?
|
|
|
|
|
I use GDI plus finish it.
|
|
|
|
|
I use GDI plus finished it.
|
|
|
|
|
Can some one pleez show uz how to use thiz or any other thing, to draw gif's (or png's) and jpeg's!
And... pleez not.. "use bla with bla..." and example of the code would be nice!
i've looked everywhere.... so pleez?
thanx!
|
|
|
|
|
void CAboutDlg::OnPaint()
{
m_cPicture->Load("1.JPG");
CWnd* pWnd = GetDlgItem(IDC_STATICPAINT);
CDC* pDC = pWnd->GetDC();
CMemDC cDC(pDC);
pWnd->Invalidate();
pWnd->UpdateWindow();
m_cPicture->Draw(&cDC,CPoint(0,0),1);
CPaintDC dc(this); // device context for painting
}
The above example draws the picture "1.JPG" i the aboutbox! IDC_STATICPAINT
is just a normel statictext placed i the dialog just as you would any other static text.
Jesper )
PS Can you help me with a dialogbox with scrollbars so that the above example kan be scrolled? I´ve desigend the aboutbox with scrollbars i resource editor but can´t seem to connect it to the picture...
|
|
|
|
|
void CAboutDlg::OnPaint()
{
m_cPicture->Load("1.JPG");
CPaintDC dc(this); // device context for painting
//CWnd* pWnd = GetDlgItem(IDC_STATICDRAW);
//CDC* pDC = pWnd->GetDC();
CDC* pDC = GetDC();
CMemDC cDC(pDC);
m_cPicture->Draw(&cDC,CPoint(10,10),1);
}
I´ve modified my last reply so that you draw directly in the dialog
Jesper )
|
|
|
|
|
I found this on Microsoft website (see below), as an example how to save pictures. The SaveAsFile function sets the Length to the right amount. But the file seems to be corrupted (About twice the size as the original) Did anyone find a solution to this?
void CPicture::SaveThePicture()
{
IPicture* pPicture = 0;
HRESULT hr = m_pPicture->QueryInterface(IID_IPicture,(void **)&pPicture);
if(SUCCEEDED(hr))
{
IStorage* pStg = 0;
hr = ::StgCreateDocfile(L"E:\\pictures\\mypicture.jpg",
STGM_SHARE_EXCLUSIVE |
STGM_CREATE |
STGM_READWRITE,
0, &pStg);
if(SUCCEEDED(hr))
{
IStream* pStream = 0;
hr = pStg->CreateStream(L"PICTURE",
STGM_SHARE_EXCLUSIVE |
STGM_CREATE |
STGM_READWRITE,
0, 0, &pStream);
if(SUCCEEDED(hr))
{
LONG Length;
hr = pPicture->SaveAsFile(pStream,
FALSE,
&Length);
pStream->Release();
}
pStg->Release();
}
pPicture->Release();
}
}
|
|
|
|
|
This appears to fail because an IStorage file is like a file-system within a file - you actually need to copy the IStream file data to a "normal" file. Here is how I do it (it's long winded but it works fine):
// Create the IStorage needed
IStorage* pStorage = NULL;
// Convert the name
WCHAR wName[MAX_PATH];
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCTSTR)"TEST.TMP", -1, wName, MAX_PATH);
// Create the storage
if (::StgCreateDocfile(wName, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE,
0, &pStorage) != ERROR_SUCCESS)
{
return false;
}
// Use the COleStreamFile class
COleStreamFile file;
// Create
if (!file.CreateStream(pStorage, "PICTURE"))
{
pStorage->Release();
return false;
}
// Save
LONG lSize = 0;
// Save the data
HRESULT hResult = m_pPicture->SaveAsFile(file.GetStream(), FALSE, &lSize);
// Success?
if (!SUCCEEDED(hResult))
{
pStorage->Release();
return false;
}
// Create the final output file
CFile fileOut;
// Open
if (!fileOut.Open("PICTURE.JPG", CFile::modeCreate|CFile::modeWrite))
{
pStorage->Release();
return false;
}
// Allocate a read buffer
BYTE* pBuffer = new BYTE [PIC_BUFSIZE];
// Be defensive
if (pBuffer == NULL)
{
pStorage->Release();
return false;
}
// Write to a real file
file.SeekToBegin();
// Loop
while (true)
{
// Read...
UINT nBytesRead = file.Read(pBuffer, PIC_BUFSIZE);
// Write...
fileOut.Write(pBuffer, nBytesRead);
// Are we done?
if (nBytesRead < PIC_BUFSIZE)
break;
}
// Release
pStorage->Release();
// Done
return true;
|
|
|
|
|
Great piece of work, does its job fine in a CFormView!
But I could not manage to get it working in a CDialog (there is no WM_DRAW Message in Dialogs)
and I got a bit confused with DCs ...
Has anyone a hint?
Guenter
|
|
|
|
|
It's a wonderful and useful class. But I encountered a problem when using the class.
The class seems to support MM_TEXT mapping mode only. When I change the dc mapping mode to MM_LOGICAL, the picture can not be drawed on the dc properly. I tried to pass parameters [CPoint(100, -100), CSize(100, -100)] to method Draw(...) instead of [CPoint(100, 100), CSize(100, 100)], but it didn't work, too.
I hope someone could help me. Thanks.
|
|
|
|
|