|

Introduction
In this article I want to show the following:
- load, convert and save various file formats (tif, bmp, jpeg, ico, jif,
jfif, koa, pcd, pcx, png, pbm, pgm, ppm, ras, targa, tga)
- supporting multipage-images
- convert color-model (1bit ... 256 colors ... 16 bit ... 24 bit ... 32 bit)
- tile the images in horizontal or vertical order
- integrating freeimage in own projects
- a sample mdi application with some simple techniques like
explorer-drag/drop
a file-open-box for selecting multiple files
background-threads for long-duration-tasks (e.g. loading images)
- zooming and scrollbars
- improved drawing-speed (using the clipping region)
- drag/drop from explorer
The Graphics-Suite
Opening and Saving
These functions are implemented using freeimage (see below). The code for
opening and saving looks is very simple and looks like this (simplified):
BOOL CGraphicSuiteDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
FREE_IMAGE_FORMAT fif;
DeleteContents();
fif = FreeImage_GetFIFFromFilename(lpszPathName);
if( fif != FIF_UNKNOWN )
m_handleFI = FreeImage_Load(fif, lpszPathName);
return (m_handleFI != NULL);
}
void CGraphicSuiteDoc::OnFileSaveAs()
{
CString filter,
szDest;
DWORD dwFlags = OFN_OVERWRITEPROMPT |
OFN_EXPLORER |
OFN_LONGNAMES |
OFN_PATHMUSTEXIST |
OFN_HIDEREADONLY;
FREE_IMAGE_FORMAT fif;
BOOL bErg;
filter.LoadString(IDS_STRING_FILTER_GRAPHICS);
CFileDialog dlg(FALSE, NULL, szDest, dwFlags, filter,
AfxGetMainWnd());
if( dlg.DoModal() != IDOK)
return;
fif = FreeImage_GetFIFFromFilename(dlg.GetPathName());
if( fif == FIF_UNKNOWN )
{
AfxMessageBox("Unknown type.");
return;
}
bErg = FALSE;
try
{
bErg = FreeImage_Save(fif, m_handleFI, dlg.GetPathName());
}
catch(...)
{
}
if( !bErg )
AfxMessageBox("Failed saving !");
}
Display and Printing
The MDI-sample uses freeimage to do all the image-stuff, except the display.
In this sample the display is handled using the API-function
StretchDIBits.
In the real-code also the clip-box is used in order only to extract the pixels
that have to be repainted. Thus the code shown here is a little simplified to
the the technique. I've choosen mapping-mode
MM_HIMETRIC, because then you can print the images using the correct
resolution and metrics.
void CGraphicSuiteView::OnDraw(CDC* pDC)
{
CGraphicSuiteDoc *pDoc = GetDocument();
pDC->SetMapMode(MM_HIMETRIC);
double dpiX = FreeImage_GetDotsPerMeterX(pDoc->m_handleFI),
dpiY = FreeImage_GetDotsPerMeterY(pDoc->m_handleFI),
width = FreeImage_GetWidth(pDoc->m_handleFI),
height = FreeImage_GetHeight(pDoc->m_handleFI),
sizeX,
sizeY;
BYTE *pData = FreeImage_GetBits(pDoc->m_handleFI);
if( dpiX==0.0 ) dpiX = 72.0 * 100.0 / 2.54;
if( dpiY==0.0 ) dpiY = 72.0 * 100.0 / 2.54;
sizeX = m_Zoom * 100.0 * 1000.0 * width / dpiX;
sizeY = m_Zoom * 100.0 * 1000.0 * height / dpiY;
::StretchDIBits(pDC->m_hDC,
sizeX, -sizeY,
(int)(sizeX+0.5), -(int)(sizeY+0.5),
0, 0,
(int)(width+0.5), (int)(height+0.5),
pData,
FreeImage_GetInfo(pDoc->m_handleFI),
DIB_RGB_COLORS,
SRCCOPY
);
}
.. or use (see code for how the parameters are to be initialized)
::SetDIBitsToDevice(
pDC->m_hDC,
xDst, yDst,
dxSrc, dySrc,
xSrc, ySrc,
0,
FreeImage_GetHeight(pFIBitmap),
FreeImage_GetBits(pFIBitmap),
FreeImage_GetInfo(pFIBitmap),
DIB_RGB_COLORS);
Image information
To complete the program, the relevant image information is shown in a dialog:

FreeImage
(Text taken from the
freeimage-introduction ! )
What is freeimage ?
FreeImage is an Open Source library project for developers who would like to
support popular graphics image formats like BMP, JPEG, TIFF and PCX and others
as needed by today's multimedia applications. The libraries comes in two
versions: a binary distribution that can be linked against any 32-bit c++
compiler and a source distribution. Workspace files for Microsoft Visual C++ 6
are provided, as well as makefiles for linux.
Features of freeimage
Freeimags-Internals
Freeimage loads the various file-formats using different libraries, e.g.
libtiff or zlib. When loading a file, the data is converted internally using the
structure
BITMAPINFO from the Win32-API (even when it is compiled
under linux). This approach makes it easy converting from format x to format y.
To support a specific file-format there are needed only 2 converters, one for
loading from the file to a
BITMAPINFO and the other for saving from
BITMAPINFO into the file:
FIBITMAP *FreeImage_Load(FREE_IMAGE_FORMAT fif,
const char *filename, int flags);
BOOL FreeImage_Save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib,
const char *filename, int flags);
FREE_IMAGE_FORMAT FreeImage_GetFIFFromFilename(const char *filename);
If you need more infos, download the source, want to discuss or, even better,
want to develop additional features, you can visit the
freeimage homepage.
Some programming hints can be found here:
FreeImage
FAQ.
Credits
The code was written using:
History
| Version 1.0 |
25. Sept. 2001 |
|
| Version 2.4.2 |
7. Oct. 2001 |
- uses freeimage 2.4.2 (see
changes)
- wait-Cursor
- exception-handling while loading
|
| Version 2.5.1 |
14. March 2002 |
- loading in background thread -> gui still usable when operation is
long
- using the ClipBox: transforming only the neccessary pixels from the
buffer to the screen -> improved drawing-speed (much faster)
- uses freeimage 2.5.1 (see
changes)
|
|
Version 2.5.2 |
26. March 2002 |
- uses freeimage 2.5.2 beta 1 (see
changes)
- mouseWheel = Zoom in/out
- Progress shown in Statusbar while working in background-thread
- multipage-support
|
|
Version 2.5.3 |
22. April 2002 |
- uses freeimage 2.5.3 beta 1 (see
changes)
- fixed some problems loading gray-images and 16-bit tiff
- sample showing opening an image from a resource (click on res)
- integrated code for clipboard copy/paste
- improved drawing:
if image is not scaled: SetDIBitsToDevice(), otherwise StretchDIBits()
- some minor fixes
|
Coming versions (maybe)
- edit ontop of images
- activeX Control
- console für batch ?
- I plan to continue the Graphics-Suite to display vector-data on top of the
images. The vector-information is stored in SVG-files. For more info about SVG
see w3c
and abobe.
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 171 (Total in Forum: 171) (Refresh) | FirstPrevNext |
|
|
 |
|
|
How can I use your library such that I can trasform BMP to JPEG in memory??
I mean without loading a BMP file and saving to a JPEG file. Suppose I have a HBITMAP in memory...and using just that I want to get the equivalent JPEG file data (in memory too) so that I can write it inside a ZIP on disk.
Right now I have to open a BMP...save it to JPEG...and add the JPEG to the ZIP...off course deleteing the BMP and JPEG afterwards....this works quite slow because there is a lot overhead on the harddisk. By doing it in memory (much faster) I will only do one operation (write) on the disk.
Thanks in advance for any suggestions 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I use vs2005 to open the project.but when compiling ,there is something wrong.So i think if this project is build in VC6.0 . I want to know if there is some way I can open it with vs2005.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
I have the same problem. After I converted the project into VC2005 and tried to build it, I got the error message:
c:\graphicsuite_src\freeimage\freeimage.h(204) : error C2383: 'FI_AllocateProc' : default-arguments are not allowed on this symbol
Could the author have a look at this problem?
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
I'm using the FreeImage 3.10.0 libraries. I compiled the FreeImage project and generated the FreeImage.lib FreeImaged.lib Then I tried to run the "fiptest" program in C++.And I included above libraries to project. But there are link errors comming I can't find where I go wrong. [Error List] Error 59 error LNK2001: unresolved external symbol "private: static union half::uif const * const half::_toFloat" (?_toFloat@half@@0QBTuif@1@B) d:\Lerning\l4s2\downloaded\FreeImage3100Win32(2)\FreeImage\Wrapper\FreeImagePlus\test\FreeImaged.lib 1 Error 74 error LNK2001: unresolved external symbol "private: static unsigned short const * const half::_eLut" (?_eLut@half@@0QBGB) d:\Lerning\l4s2\downloaded\FreeImage3100Win32(2)\FreeImage\Wrapper\FreeImagePlus\test\FreeImaged.lib 1 Error 55 error LNK2001: unresolved external symbol "public: __thiscall Iex::BaseExc::BaseExc(class Iex::BaseExc const &)" (??0BaseExc@Iex@@QAE@ABV01@@Z) d:\Lerning\l4s2\downloaded\FreeImage3100Win32(2)\FreeImage\Wrapper\FreeImagePlus\test\FreeImaged.lib 1 Error 61 error LNK2001: unresolved external symbol "public: virtual bool __thiscall Imf::IStream::isMemoryMapped(void)const " (?isMemoryMapped@IStream@Imf@@UBE_NXZ) d:\Lerning\l4s2\downloaded\FreeImage3100Win32(2)\FreeImage\Wrapper\FreeImagePlus\test\FreeImaged.lib 1 Error 62 error LNK2001: unresolved external symbol "public: virtual char * __thiscall Imf::IStream::readMemoryMapped(int)" (?readMemoryMapped@IStream@Imf@@UAEPADH@Z) d:\Lerning\l4s2\downloaded\FreeImage3100Win32(2)\FreeImage\Wrapper\FreeImagePlus\test\FreeImaged.lib 1 Error 57 error LNK2001: unresolved external symbol "public: virtual char const * __thiscall Iex::BaseExc::what(void)const " (?what@BaseExc@Iex@@UBEPBDXZ) d:\Lerning\l4s2\downloaded\FreeImage3100Win32(2)\FreeImage\Wrapper\FreeImagePlus\test\FreeImaged.lib 1 Error 28 error LNK2001: unresolved external symbol _cio_tell d:\Lerning\l4s2\downloaded\FreeImage3100Win32(2)\FreeImage\Wrapper\FreeImagePlus\test\FreeImaged.lib 1 Error 12 error LNK2001: unresolved external symbol _opj_cio_close d:\Lerning\l4s2\downloaded\FreeImage
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |
|
|
I have downloaded the FreeImage 3.10.0 version It is for windows xp.But I can't run the test(flip test) project included in the distribution. I run the application in VS 2005.
get the error fatal error LNK1181: cannot open input file 'FreeImaged.lib' fipTest But I couldn't find a 'FreeImaged.lib' in the distribution.
Appreciate a Quick reply
regards
THilani
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
Hi,
Great program  I want to use it to convert the DIB I receive from the screen with out the need to save it as BMP and then load it with your program. Same thing backwords, convert the PNG to DIB in memory. Is there a way to do it? Why don't you give the FreeImage.dll source code?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi. I need to use this dll in my C#.NET Application.But while trying to add it in add reference.it generate error as "This is not valid COM file" Help
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
Nice work and I would use it but when I try to load LZW tif file I receive a message "LZW compression is no longer supported..." Even if I want to ask just for the resolution or size of the file I can't. In fact I have a Unisys license but can't work with the LZW files using the library. Library should give the opportunity to load and open LZW files and the responsibility using files like this is for the user Kind regards,
Trifon Alekov
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hi.
This is what I'm getting:
Error C2383 'symbol' : default-arguments are not allowed on this symbol.
Which refer to the FreeImage.h file at the line:
typedef FIBITMAP *(DLL_CALLCONV *FI_AllocateProc)(int width, int height, int bpp, unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0));
I think that I understand the meaning of the error; I have to get rid of the default inisialization (0). I've tried that and it does not work. I've tried a few other things too, and no success.
What to do?
|
| Sign In·View Thread·PermaLink | 3.00/5 (2 votes) |
|
|
|
 |
|
|
Nevermind guys...I used VC++ 6 and did a release...working now. Having alot of problems with .NET 2003 thou!!!
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |
|
|
Whenever I try to complie the project using VC++ 6 it gives this error.. "fatal error LNK1104: cannot open file "FreeImageD.lib""... plz someone help me out..
|
| Sign In·View Thread·PermaLink | 1.40/5 (5 votes) |
|
|
|
 |
|
|
1. Build -> Clean 2. Project -> Set Active Project -> Win32 Release
Complile and it should work!
Dave
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
Sorry....I've made tiny a mistake.
1. Build -> Clean 2. Build (not Project) -> Set Active Project -> Win32 Release
Complile and it should work!
P.S. I suggest that you re-download the entire project first and then, do the step above.
Dave
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
I just downloaded the FreeImage project and I thought I'd try out the binary (executable) before looking at any source code. I loaded 4 x TGA files into the viewer but they all came out upside down (and clipped on one edge). I then tried re-saving them as JPEGs - but I got a message saying that only 24-bit highcolor and 8-bit grayscale Targa's can be converted to JPEG (I think that these are 32-bit).
However, I have other image viewers that display the TGA images correctly and also allow them to be converted to JPEG. I just wondered if these are known problems?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
UPDATE - I tried this with a more recent version of the FreeImage library and it's now working fine.
Well, at least the "upside down and clipped" problem has gone away - but I still can't save a 32-bit Targa image as a JPEG.
However, I think that's a problem with FreeImage :(
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
It's not so much a 'problem' with FreeImage, but rather a design choice. FreeImage won't automagically convert bitmaps prior to saving them. If you have a 32-bit image, you have to manually call FreeImage_ConvertTo24Bits() in order to convert it. You can then save the resulting image.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello, I program with VC++ 6 with MFC. I saw that if I open more bitmaps with follow code
FIBITMAP * dib = FreeImage_Load(fif, FileName) then I can to select one bitmap and save them with the follow code FreeImage_Save(fif, dib, dlg.GetPathName) With dlg i mean the Opendialog where I add the filename.
If I allocate more bitmaps FIBITMAP * dib2 = FreeImage_Allocate(Rows, Cols, bpp) I want also to save the selected bitmap and not the last allocated bitmap. If I assign all bitmaps to dib2, then dib2 will every time signed over with the last bitmap. Thanks. Lilia
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Each time you call FreeImage_Load or FreeImage_Allocate memory is allocated and a pointer is returned to that memory. If you repeatedly overwrite that pointer you will not only lose the other bitmap but also introduce a memory leak. It's better to create an array of bitmaps.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi
I have a school assignmemt which required to convert a tiff file to bmp file automatically. the Tiff files is send to the computer through an attach camara.
I would like to know how can i change to above program to suit me school assignment.
the reason why i can't use the above program is that user still have to click on the "File -> Open" buttton and "Save As" button. Can the program be re-code so as this step can be skip.
Thank for reading my problem. Wish everyone a happy new year.
Regards Eric
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
The link in this article is broken (FreeImage isn't listed anywhere on the site you are sent to), so go here for your freeimage lovin':
http://freeimage.sourceforge.net/[^]
It's up to version 3.80 and it supports VC++ 6.0, .NET, C#, VB, and Linux. The Source for the library is written in C++ and is available on sourceforge along with a pdf document.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|