|
Could you please send me a sample-pcd per email in order to test and correct my code (markus.loibl@epost.de)
Thanks in advance
|
|
|
|
|
FreeImage is not capable of loading the largest two resolutions of a PhotoCD file. This is because so far these two resolutions are not documented in any way, and i've not been able to reverse engineer them either. If anyone can provide me with any theory or code, i'm interested.
Floris (lead author of FreeImage)
|
|
|
|
|
and display it inside a client dc ??
I load the bitmap to a HGLOBAL, as an example said
on the freeimage web site "convert a HBitmap to a FreeImage", in print preview everything is correct, but as a printer output I get only a black rectangle, where the image should be placed, don't know why ?? Any help ???
How do i convert a HBITMAP to a FreeImage image?
--------------------------------------------------------------------------------
BITMAP bmp;
GetObject(hbmScreen, sizeof(BITMAP), (LPSTR)&bmp);
int cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
FIBITMAP *dib = FreeImage_Allocate(bmp.bmWidth, bmp.bmHeight, cClrBits );
GetDIBits(hdcScreen, hbmScreen, 0, bmp.bmHeight, FreeImage_GetBits(dib),
FreeImage_GetInfo(dib), DIB_RGB_COLORS);
|
|
|
|
|
In the updated code this is implemented as an example
Simply click on the "Res" button
Markus Loibl
|
|
|
|
|
Thx a lot, I have been away from this site for a while,
but I have now found another way, what is much better if you want to display large logos above each print preview for example.
If you have a lot of large images then it is not so good to place them inside the resource of your project, because if for example the bmp is about 1 MB large then your exe file will enlarge also by 1 MB. So I found another way, I created an extern zip file, which includes all the logos and images that I want to display on my printing pages and the compressed file size of a bmp that is grey scaled and is about 1 MB in original size, then in compressed format it is only 25 kB large, so you can save a lot of disk space for your installation files. Then I included a ZIP/UNZIP class from anywhere (think I found it on CodeProject size), when starting my program, I unzip all the images that I need to a temp folder and load the unzipped images when I display my print preview or do my printing.
But I will look at your code and see, how it has been solved to load a bitmap from the resource, maybe I will implement your way.
|
|
|
|
|
Thats true.
I included the code for educational purposes only. Of course you can load resourcesd from somewhere else, e.g. from the file or from the clipboard. As you can see in the new code, I included a routine
CGraphicSuiteApp::OpenFromBitmap(HBITMAP hBitmap)
You can use this the following way:
CBitmap bmp;
// Load the bitmap
bmp.LoadBitmap("c:\temp\sample.bmp");
HBITMAP hBitmap = (HBITMAP) bmp;
OpenFromBitmap(hBitmap);
|
|
|
|
|
Thx a lot anyway,
with the freeimage lib and your implementation in MFC or Visual C++ you can save a lot of money, in formerly days I bought some classes from Stingray (Objective Toolkit), now it is owned by Roguewave and is very expensive, next I bought the Ultimate Toolbox from Dundas, and afterwards, because of the lot of bitmap file formats that was growing I suggested to buy LeadTools ocx, but for the most purposes your class implementation has all the features that I need.
So you can forget most of the commercial tools and I only implemented the freeimage class.
Great job, I now really have found what I was looking for for about 10 years.....
Thx a lot again,
Michael Kuelshammer
|
|
|
|
|
Thanks,
and as we would say in germany: "Das geht runter wie Butter"
|
|
|
|
|
It doesn't appear that FreeImage currently supports handling of 16-bit grayscale images (commonly used for medical applications, etc..).
Is this correct?
|
|
|
|
|
Are you speaking of dicom ?
Do you have sample-images?
please send them to markus.loibl@epost.de
|
|
|
|
|
In the updated code this should work
Markus Loibl
|
|
|
|
|
there are some problems about save a FIBitmap which converted from HBitmap:
I got a HBITMAP from a bitmap file and convert the HBITMAP to a FIBITMAP.the FIBITMAP can be drawn on SCREEN by useing SetDIBitsToDevice();Now i want to save the FIBITMAP as a jpg file.but the FreeImage_Save() return 0.
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//convert a HBITMAP image to a FIBITMAP
BOOL CFreeTestView::CreateFIFromBitmap(HBITMAP hBMP,FIBITMAP * & pFIBMP)
{
BITMAP bm;
if(pFIBMP != NULL)
FreeImage_Free(pFIBMP);
::GetObject(hBMP,sizeof(bm),&bm);
int cClrBits = (WORD)(bm.bmPlanes * bm.bmBitsPixel);
pFIBMP = FreeImage_Allocate(bm.bmWidth,bm.bmHeight,cClrBits);
HDC hdcImg = CreateCompatibleDC( NULL ); // copy HBITMAP's bits to FIBITMAP
int nRet = GetDIBits(hdcImg,hBMP,0,bm.bmHeight,FreeImage_GetBits(pFIBMP),
FreeImage_GetInfo(pFIBMP),DIB_RGB_COLORS);
....
}
.........
//the hbitmap loaded from test.bmp file
CreateFIFromBitmap(hbitmap,&fibitmap);
.........
bErg = FreeImage_Save(fif, m_fibitmap, dlg.GetPathName()/*Tst.jpg*/);
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
|
|
|
|
|
Be shure your Bitmap is in 24bit format or
convert it to 24bits before calling the save-function.
|
|
|
|
|
i did try to view couple 16-bit bmp's, colors was wrong.
will send a test images on request: gok@aeromap.com
gennady
|
|
|
|
|
In the updated code this should work
Markus Loibl
|
|
|
|
|
see also http://www.codetools.com/bitmap/graphicsuite.asp?forumid=2668&select=140996#xx140996xx
You have to insert a button into the toolbar. Implement the clicking on it like this:
void CGraphicSuiteView::OnEditCopy()
{
CGraphicSuiteDoc *pDoc = GetDocument();
FIBITMAP *pFIBitmap = (pDoc ? pDoc->GetFIBitmap() : NULL);
int pageCount = (pDoc ? pDoc->GetPageCount() : 0),
currPage = (pDoc ? pDoc->GetCurrPage() : 0);
int type = (pFIBitmap ? FreeImage_GetColorType(pFIBitmap) : 0);
if( !pFIBitmap )
return;
try
{
if( type == FIC_MINISWHITE || type == FIC_MINISBLACK )
{
CWindowDC dc(NULL);
CDC hdc ;
hdc.CreateCompatibleDC(&dc);
HBITMAP bitmap = CreateDIBitmap(hdc.GetSafeHdc(),
FreeImage_GetInfoHeader(pFIBitmap),
CBM_INIT,
FreeImage_GetBits(pFIBitmap),
FreeImage_GetInfo(pFIBitmap),
DIB_RGB_COLORS);
if( bitmap != NULL )
{
AfxGetApp()->m_pMainWnd->OpenClipboard();
EmptyClipboard() ;
SetClipboardData(CF_BITMAP, bitmap );
CloseClipboard() ;
}
}
else
{
CWindowDC dc (this);
//----------------------
// Create a bitmap copy:
//----------------------
CDC memDCDest;
memDCDest.CreateCompatibleDC (NULL);
CDC memDCSrc;
memDCSrc.CreateCompatibleDC (NULL);
HBITMAP bitmap = CreateDIBitmap(dc.GetSafeHdc(),
FreeImage_GetInfoHeader(pFIBitmap),
CBM_INIT,
FreeImage_GetBits(pFIBitmap),
FreeImage_GetInfo(pFIBitmap),
DIB_RGB_COLORS);
CBitmap *pBitmapCopy = CBitmap::FromHandle(bitmap);
if( !bitmap || !pBitmapCopy )
{
AfxMessageBox ("Can't copy bitmap");
return;
}
// CBitmap* pOldBitmapDest = memDCDest.SelectObject (pBitmapCopy);
CBitmap* pOldBitmapSrc = memDCSrc.SelectObject (pBitmapCopy);
memDCDest.BitBlt (0, 0, FreeImage_GetWidth(pFIBitmap),
FreeImage_GetHeight(pFIBitmap),
&memDCSrc, 0, 0, SRCCOPY);
// memDCDest.SelectObject (pOldBitmapDest);
memDCSrc.SelectObject (pOldBitmapSrc);
if (!OpenClipboard ())
{
AfxMessageBox ("Can't copy bitmap");
return;
}
if (!::EmptyClipboard ())
{
AfxMessageBox ("Can't copy bitmap");
::CloseClipboard ();
return;
}
HANDLE hclipData = ::SetClipboardData (CF_BITMAP, pBitmapCopy->Detach ());
if (hclipData == NULL)
{
AfxMessageBox ("Can't copy bitmap");
}
::CloseClipboard ();
}
}
catch (...)
{
AfxMessageBox ("Can't copy bitmap");
}
}
void CGraphicSuiteView::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
CGraphicSuiteDoc *pDoc = GetDocument();
FIBITMAP *pFIBitmap = (pDoc ? pDoc->GetFIBitmap() : NULL);
pCmdUI->Enable(pFIBitmap!=NULL);
}
Markus Loibl
|
|
|
|
|
Hi,
can you give a code snipset how to read an image
into an opengl texture ?
Thanx,
Howie
|
|
|
|
|
Sorry, no.
I have no idea about opengl.
Markus Loibl
|
|
|
|
|
Perhaps the above remark "Code for Copy image to clipboard" can help you; it shows how to access the pixmap
Markus Loibl
|
|
|
|
|
sorry !there are some error on my last message!
that is my routine:
BOOL CFreeTestView::CreateBitmapFromFI(FIBITMAP *fiBMP,HBITMAP &phbmBMP)
{
// create a mem DC
CWindowDC dc(this);
CDC hdc ;
hdc.CreateCompatibleDC(&dc);
_ASSERT( hdc );
BITMAPFILEHEADER *pHeader;
BITMAPINFO *pbmInfo;
pbmInfo = FreeImage_GetInfo(fiBMP);
pHeader = (BITMAPFILEHEADER *)FreeImage_GetInfoHeader(fiBMP);
LPVOID pData = FreeImage_GetBits(fiBMP);
//create a HBitmap from FIBitmap
phbmBMP = CreateDIBitmap(hdc.GetSafeHdc(),
&pbmInfo->bmiHeader,
CBM_INIT,
pData,
pbmInfo,
DIB_RGB_COLORS);
......
}
when i display the HBITMAP converted from FIBITMAP.
there is a black rectangle in my screen.
why.....
|
|
|
|
|
see http://www.6ixsoft.com/developer.html#faq
----------------------------------------------------------------
How do i draw a FreeImage image to the screen in Windows?
FIBITMAP *dib = FreeImage_LoadBMP("test.bmp", BMP_DEFAULT);
SetDIBitsToDevice(hdc, x, y, FreeImage_GetWidth(dib),
FreeImage_GetHeight(dib), 0, 0, 0,
FreeImage_GetHeight(dib), FreeImage_GetBits(dib),
FreeImage_GetInfo(dib), DIB_RGB_COLORS);
----------------------------------------------------------------
How do i convert a FreeImage image to a HBITMAP?
FIBITMAP *dib = FreeImage_LoadBMP("test.bmp", BMP_DEFAULT);
HBITMAP bitmap = CreateDIBitmap(hdc,
FreeImage_GetInfoHeader(dib),
CBM_INIT,
FreeImage_GetBits(dib),
FreeImage_GetInfo(dib),
DIB_RGB_COLORS);
----------------------------------------------------------------
How do i convert a HBITMAP to a FreeImage image?
BITMAP bmp;
GetObject(hbmScreen, sizeof(BITMAP), (LPSTR)&bmp);
int cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
FIBITMAP *dib = FreeImage_Allocate(bmp.bmWidth, bmp.bmHeight, cClrBits );
GetDIBits(hdcScreen, hbmScreen, 0, bmp.bmHeight, FreeImage_GetBits(dib),
FreeImage_GetInfo(dib), DIB_RGB_COLORS);
|
|
|
|
|
thank u for your answer!
I tried to convert a FIBitmap to a HBITMAP. but i failed to do it yet.when i create a new HBITMAP with CreateDIBitmap() . the method return NULL.
|
|
|
|
|
I've tested the code above with the following statements:
void CGraphicSuiteView::OnCopyToClipboard()
{
CGraphicSuiteDoc *pDoc = GetDocument();
FIBITMAP *pFIBitmap = (pDoc ? pDoc->GetFIBitmap() : NULL);
int pageCount = (pDoc ? pDoc->GetPageCount() : 0),
currPage = (pDoc ? pDoc->GetCurrPage() : 0);
if( !pFIBitmap )
return;
CWindowDC dc(NULL);
// RGBQUAD *pal = FreeImage_GetPalette(pFIBitmap);
CDC hdc ;
hdc.CreateCompatibleDC(&dc);
// hdc.SelectPalette(
HBITMAP bitmap = CreateDIBitmap(hdc.GetSafeHdc(),
FreeImage_GetInfoHeader(pFIBitmap),
CBM_INIT,
FreeImage_GetBits(pFIBitmap),
FreeImage_GetInfo(pFIBitmap),
DIB_RGB_COLORS);
if( bitmap != NULL )
{
AfxGetApp()->m_pMainWnd->OpenClipboard();
EmptyClipboard() ;
SetClipboardData(CF_BITMAP, bitmap );
CloseClipboard() ;
}
}
In the clipboard there's only a b/w-bitmap. A normal full-colored-picture seems to be just black (really its not only black, but just 1 bit with b/w), and a 1bit-picture is correctly transferrred to the clipboard.
I'll try to find out what's still missing (CF_PALETTE, CDC::SetPalette, ... ??) and will include the code then into the application in order to copy an image into the clipboard !
This will take 2-3 weeks as I'm not at home for 2 weeks from tomorrow!
Markus Loibl
|
|
|
|
|
I just found a solution to copy the stuff to the clipboard. This should help you to fix your code:
void CGraphicSuiteView::OnEditCopy()
{
CGraphicSuiteDoc *pDoc = GetDocument();
FIBITMAP *pFIBitmap = (pDoc ? pDoc->GetFIBitmap() : NULL);
int pageCount = (pDoc ? pDoc->GetPageCount() : 0),
currPage = (pDoc ? pDoc->GetCurrPage() : 0);
int type = (pFIBitmap ? FreeImage_GetColorType(pFIBitmap) : 0);
if( !pFIBitmap )
return;
try
{
if( type == FIC_MINISWHITE || type == FIC_MINISBLACK )
{
CWindowDC dc(NULL);
CDC hdc ;
hdc.CreateCompatibleDC(&dc);
HBITMAP bitmap = CreateDIBitmap(hdc.GetSafeHdc(),
FreeImage_GetInfoHeader(pFIBitmap),
CBM_INIT,
FreeImage_GetBits(pFIBitmap),
FreeImage_GetInfo(pFIBitmap),
DIB_RGB_COLORS);
if( bitmap != NULL )
{
AfxGetApp()->m_pMainWnd->OpenClipboard();
EmptyClipboard() ;
SetClipboardData(CF_BITMAP, bitmap );
CloseClipboard() ;
}
}
else
{
CWindowDC dc (this);
//----------------------
// Create a bitmap copy:
//----------------------
CDC memDCDest;
memDCDest.CreateCompatibleDC (NULL);
CDC memDCSrc;
memDCSrc.CreateCompatibleDC (NULL);
HBITMAP bitmap = CreateDIBitmap(dc.GetSafeHdc(),
FreeImage_GetInfoHeader(pFIBitmap),
CBM_INIT,
FreeImage_GetBits(pFIBitmap),
FreeImage_GetInfo(pFIBitmap),
DIB_RGB_COLORS);
CBitmap *pBitmapCopy = CBitmap::FromHandle(bitmap);
if( !bitmap || !pBitmapCopy )
{
AfxMessageBox ("Can't copy bitmap");
return;
}
// CBitmap* pOldBitmapDest = memDCDest.SelectObject (pBitmapCopy);
CBitmap* pOldBitmapSrc = memDCSrc.SelectObject (pBitmapCopy);
memDCDest.BitBlt (0, 0, FreeImage_GetWidth(pFIBitmap),
FreeImage_GetHeight(pFIBitmap),
&memDCSrc, 0, 0, SRCCOPY);
// memDCDest.SelectObject (pOldBitmapDest);
memDCSrc.SelectObject (pOldBitmapSrc);
if (!OpenClipboard ())
{
AfxMessageBox ("Can't copy bitmap");
return;
}
if (!::EmptyClipboard ())
{
AfxMessageBox ("Can't copy bitmap");
::CloseClipboard ();
return;
}
HANDLE hclipData = ::SetClipboardData (CF_BITMAP, pBitmapCopy->Detach ());
if (hclipData == NULL)
{
AfxMessageBox ("Can't copy bitmap");
}
::CloseClipboard ();
}
}
catch (...)
{
AfxMessageBox ("Can't copy bitmap");
}
}
Markus Loibl
|
|
|
|
|
that is my routine:
BOOL CFreeTestView::CreateBitmapFromFI(FIBITMAP *fiBMP,HBITMAP &phbmBMP)
{
// create a mem DC
CWindowDC dc(this);
CDC hdc ;
hdc.CreateCompatibleDC(&dc);
_ASSERT( hdc );
BITMAPFILEHEADER *pHeader;
BITMAPINFO *pbmInfo;
pbmInfo = FreeImage_GetInfo(fiBMP);
pHeader = (BITMAPFILEHEADER *)FreeImage_GetInfoHeader(fiBMP);
LPVOID pData = FreeImage_GetBits(fiBMP);
//create a DIBitmap from FIBitmap
phbmBMP = CreateDIBitmap(hdc.GetSafeHdc(),
&pbmInfo->bmiHeader,
CBM_INIT,
pData,
pbmInfo,
DIB_RGB_COLORS);
......
}
when i display the FIBITMAP converted from HBITMAP.there is a black rectangle in my screen.
why.....
|
|
|
|
|