Discussion:
how to use freeimage
(too old to reply)
Aegis Delacour
2009-09-01 08:53:10 UTC
Permalink
hey there,

im totally new to VS/VC
ive never installed an external library..

could someone tell me how do i install the freeimage library as i need
to load an image.

thank you
Brian Muth
2009-09-01 18:40:50 UTC
Permalink
The distribution is very simple. It contains one header file. I assume as a
C/C++ programmer you know that that is for. There is a lib file that must be
referenced under the project's Properties, Configuration Properties, Linker,
Input, Additional Dependencies. And finally there is a DLL which must be
accessible to the executable. You can copy it to the same folder as the
executable, or in any of the folders defined by your PATH environment
variable:

http://msdn.microsoft.com/en-us/library/ms682586(VS.85).aspx

Brian
Alain
2009-09-02 05:41:12 UTC
Permalink
Post by Aegis Delacour
hey there,
im totally new to VS/VC
ive never installed an external library..
could someone tell me how do i install the freeimage library as i need
You don't need any external library on Windows.
Why do you want to use freeimage or anything else, when everything is native
with Windows api, for all image formats ?!
Aegis Delacour
2009-09-03 01:36:51 UTC
Permalink
Post by Alain
Post by Aegis Delacour
hey there,
im totally new to VS/VC
ive never installed an external library..
could someone tell me how do i install the freeimage library as i need
You don't need any external library on Windows.
Why do you want to use freeimage or anything else, when everything is native
with Windows api, for all image formats  ?!
well thats cause i dont know how to haha
care to help?
i need it to display a jpg
Alex Blekhman
2009-09-03 06:57:23 UTC
Permalink
Post by Aegis Delacour
well thats cause i dont know how to haha
care to help?
i need it to display a jpg
Generally people here care to help, but your description of the
problem so vague, that it is impossible to give you a meaningful
answer. You should describe more elaborately what is your goal.

Alex

P.S.
"De la bonne manière de poser les questions"
http://www.gnurou.org/writing/smartquestionsfr
Aegis Delacour
2009-09-03 07:47:56 UTC
Permalink
oops, well heres the thing..i need to display a .jpg in fullscreen
but the image will be the entire screens size. I have finished the
screenshot function. Now i need to just display it and thats it.

I did some research and found this but i do get a few errors. Maybe
someone can debug it? or perhaps theres an easier way to do this. I
have commented exactly where the errors are.


C:\Documents and Settings\Administrator\Desktop\Copy of Lower EICAS
(240709)\LowerEicasDlg.cpp(27050) : error C2660: 'GetDC' : function
does not take 1 parameters
C:\Documents and Settings\Administrator\Desktop\Copy of Lower EICAS
(240709)\LowerEicasDlg.cpp(27057) : error C2065: 'HIMETRIC_INCH' :
undeclared identifier
C:\Documents and Settings\Administrator\Desktop\Copy of Lower EICAS
(240709)\LowerEicasDlg.cpp(27060) : error C2660: 'GetClientRect' :
function does not take 2 parameters
C:\Documents and Settings\Administrator\Desktop\Copy of Lower EICAS
(240709)\LowerEicasDlg.cpp(27064) : error C2660: 'ReleaseDC' :
function does not take 2 parameters











void CLowerEicasDlg::LoadPictureFile(LPCTSTR szFile, HWND hWnd)
{
LPPICTURE gpPicture = 0;
// open file
HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL,
OPEN_EXISTING, 0, NULL);
_ASSERTE(INVALID_HANDLE_VALUE != hFile);

// get file size
DWORD dwFileSize = GetFileSize(hFile, NULL);
_ASSERTE(-1 != dwFileSize);

LPVOID pvData = NULL;
// alloc memory based on file size
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
_ASSERTE(NULL != hGlobal);

pvData = GlobalLock(hGlobal);
_ASSERTE(NULL != pvData);

DWORD dwBytesRead = 0;
// read file and store in global memory
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead,
NULL);
_ASSERTE(FALSE != bRead);
GlobalUnlock(hGlobal);
CloseHandle(hFile);

LPSTREAM pstm = NULL;
// create IStream* from global memory
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
_ASSERTE(SUCCEEDED(hr) && pstm);

// Create IPicture from image file
if (gpPicture)
gpPicture->Release();
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID
*)&gpPicture);
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release();

/** Painting part added to make it into one function **/

// Retrieve dc
HDC hdc = GetDC( hWnd ); //error1
long hmWidth = 0;
long hmHeight = 0;
gpPicture->get_Width(&hmWidth);
gpPicture->get_Height(&hmHeight);

// convert himetric to pixels
int nWidth = MulDiv(hmWidth, GetDeviceCaps(hdc, LOGPIXELSX),
HIMETRIC_INCH); //error2
int nHeight = MulDiv(hmHeight, GetDeviceCaps(hdc, LOGPIXELSY),
HIMETRIC_INCH);
RECT rc;
GetClientRect(hWnd, &rc); //error3

// display picture using IPicture::Render
gpPicture->Render(hdc, 0, 0, nWidth, nHeight, 0, hmHeight, hmWidth, -
hmHeight, &rc);
ReleaseDC( hWnd, hdc ); //error4
gpPicture->Release();

/** End Painting Part **/
}
Alex Blekhman
2009-09-03 08:54:12 UTC
Permalink
i need to display a .jpg in fullscreen but the image will be the
entire screens size. I have finished the screenshot function.
Now i need to just display it and thats it.
If you have .JPEG file on the disk, then the easiest way to show
it is to use HTML page. Here's the sample of the HTA program that
shows an image fullscreen:

<HTML>
<HEAD>
<TITLE>My Monster Application</TITLE>
<HTA:APPLICATION ID="oMyApp"
BORDER="none"
CAPTION="no"
SHOWINTASKBAR="no"
SINGLEINSTANCE="yes"
SYSMENU="no"
WINDOWSTATE="maximize">
</HEAD>
<BODY
SCROLL="no"
LEFTMARGIN="0"
TOPMARGIN="0"
RIGHTMARGIN="0"
BOTTOMMARGIN="0">
<IMG HEIGHT="100%" WIDTH="100%" SRC="path_to_the_image.jpeg" />
</BODY>
</HTML>

Copy the text above, paste it to Notepad and save as a file with
.HTA extension. When you run the file, the image will be shown
fullscreen.

Now, if you insist on doing it from C++ program, then you can use
OleLoadPictureFile[Ex] or OleLoadPicturePath functions. However,
the painting part of the code must be in WM_PAINT message handler.
In Windows a program paints its client area in response to the
WM_PAINT message.

I can see that you use MFC dialog. Instead of painting on it, just
create a picture control on the dialog. Attach a variable of the
type CStatic to it by using dialog wizard. Then at runtime resize
the control so it occupies full area of the dialog. In order to
set an image use CStatic::SetBitmap method. In order to obtain
image's HBITMAP handle call IPicture::get_Handle method.

HTH
Alex
Aegis Delacour
2009-09-03 13:12:10 UTC
Permalink
Wow..thats a very interesting way Alex, works to perfection..i could
do a ShellExecute in my program to load that file
now i wish that .hta will close when i run another function or at
least go in the background which it should..i dont have visual studio
here but i cant wait to try it out tomorrow in school.

Continue reading on narkive:
Loading...