|
Try following methods for getting..size...
For CBitmap objects we can use the GetBitmap() function to determine the height and width of the bitmap.
// The variable bitmap is a CBitmap object
BITMAP bm;
bitmap.GetBitmap( &bm );
bmWidth = bm.bmWidth;
bmHeight = bm.bmHeight;
If you have a HBITMAP, you can attach it to a CBitmap object and use the method shown above or you can use
// The variable hBmp is a HBITMAP
BITMAP bm;
::GetObject( hBmp, sizeof( bm ), &bm );
bmWidth = bm.bmWidth;
bmHeight = bm.bmHeight;
For images in a BMP file, you can use something like
CFile file;
// sBMPFileName is the BMP filename
if( !file.Open( sBMPFileName, CFile::modeRead) )
return ;
BITMAPFILEHEADER bmfHeader;
// Read file header
if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader)) != sizeof(bmfHeader))
return ;
// File type should be 'BM'
if (bmfHeader.bfType != ((WORD) ('M' << 8) | 'B')) return ;
BITMAPINFOHEADER bmiHeader;
if (file.Read((LPSTR)&bmiHeader, sizeof(bmiHeader)) != sizeof(bmiHeader))
return ;
int bmWidth = bmiHeader.biWidth;
int bmHeight = bmiHeader.biHeight;
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
Hi Sumit,
I´ve sent you this message becouse I´m having some problems while compiling the project. I believe it´s due to the kind of compiler I´m using, which is BCC 5.0.
It returns the following error message:
[C++ Fatal Error] BmptoTif.h(18): F1003 Error directive: include 'stdafx.h' before including this file for PCH
How can I adapt this code to be able to run it under BCC5.0? I´m making this question because I don´t know very much about image programing and because I´ve started to study about these things lately due to my work.
Thanks for your attention,
Letícia.
|
|
|
|
|
I please to answer all, but in your case I feel helpless..as I don't know much about Borland C++.
Include file 'stdafx.h' is used for global include. I don't know how it would be tackle by Borland.
Sorry I can;t help you much in BC++. If I can help you any more you can chat me at mine hotmail ID:
sumit_kapoor1980@hotmail.com
Regards,
Sumit K
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
Sumit,
I´ve already solved that problem, but I´ve got another and perhaps you may help me.
The compiler returns the following error msg about libtiff (the version of libtiff I´m working is 3.7.3 release date: 17 july 2005):
[Linker Error] 'D:\ESSENCIAIS\POS ENG BIOMÉDICA\TESE\AVI2BMP2TIFF\BMPTOTIF\ LIBTIFF.LIB' contains invalid OMF record, type 0x21 (possibly COFF)
And I don´t understand this error msg. Do you have any idea?
Thanks for your help!
Best regards,
Letícia.
|
|
|
|
|
Hi Dear,
As I told last time I don't have much idea about Borland C++, So I asked one of mine friend. I don't know what exactly his means, as you are using borland, so you may understand.
" Actaully in Borland, different format is used for library and this error is alerting you about that conversion. You have to convert LibTiff.lib librairy from COFF to OMF format with the Borland utilitiy coff2omf. Once you have created OMF versions, re-run cmake to tell it where the Borland versions of libtiff is located."
I think, if you are regular user of borland, you can understand and can run lib file. Or you can contact any of your friend who know more BC++, he may help you.
Regards,
Sumit Kapoor
|
|
|
|
|
Sumit,
I´d like to thank you for the help.
It worked out. And also my friend enjoyed the idea!
Best Regards,
Letícia.
|
|
|
|
|
Sumit,
I´m sorry to bother you once again, but I have a problem that I don´t know how to solve for the moment.
I used the Borland convetion utility to convert the MVC++ project into a BCC project and it worked out.
The problem is, the compiler returns these error messages:
[Linker Error] Unresolved external '_TIFFOpen' referenced from C:\TEMP\MCETOOL\AQSSOURCE\BMPTOTIF\DEBUG\BMPTOTIFDLG.OBJ
[Linker Error] Unresolved external '_TIFFSetField' referenced from C:\TEMP\MCETOOL\AQSSOURCE\BMPTOTIF\DEBUG\BMPTOTIFDLG.OBJ
[Linker Error] Unresolved external '_TIFFWriteScanline' referenced from C:\TEMP\MCETOOL\AQSSOURCE\BMPTOTIF\DEBUG\BMPTOTIFDLG.OBJ
[Linker Error] Unresolved external '_TIFFClose' referenced from C:\TEMP\MCETOOL\AQSSOURCE\BMPTOTIF\DEBUG\BMPTOTIFDLG.OBJ
These errors occur due to the folowing reason (acording to the BCC compiler):
"The named symbol is referenced in the given module but is not defined anywhere in the set of object files and libraries included in the link. Check to make sure the symbol is spelled correctly." Although the include files are all in the same directory.
I still couldn´t find somebody who can help me with this. I know you don´t work with borland compiler but if you have any clue...
Thanks for everything,
Letícia.
|
|
|
|
|
Dear Letícia,
O..I was thinking you have finished up this work, but you still struck in this..OK!..I try to get solution..
There can be two reason:
1.
------------------------------------------------------
I think you have not included header files that is given along with Library file.
Just check my source code, I have included two files in source where I am using these function..that are..
#include "tiffio.h"
#include "tiffiop.h"
The other files that are needed to include in project are:
t4.h
tif_dir.h
tif_predict.h
tiff.h
tiffcomp.h
tiffconf.h
tiffvers.h
uvcode.h
I think this would solve your problem.
2.
-------------------------------------------------------------
It may be possible that you are using functions with prefix underscore('_')..
function given in library is TIFFOpen() NOT _TIFFOpen()
Just check this also.
----------------------------------------------
Also, within 1-2 days I'll not be available(5th Nov. 2005 to 13th Nov. 2005) for any help. So please ask before/after that date range, if you have any query.
Regards,
Sumit K
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
For borland c++ builder 5&6, maybe you already figured this out or dont care anymore by now, but
Just add to your main project .cpp file a uselib statement:
USELIB("libtiff.lib");
and then add the include and lib paths of the library to the include and lib paths of the borland c++ project.
Also use coff2omf to convert the lib as already stated...ie
first rename libtiff.lib to libtiff_coff.lib
coff2omf libtiff_coff.lib libtiff.lib
Also add libtiff.lib to your project as a project file.
It will compile and run fine after doing all this...
Put the .dll files in your project directory for ease during development.
later
NixDude
|
|
|
|
|
Hi Sumit,
I would like to know why the compiler returns this message (External Exception C0FB0070) every time I call "ConvertToTiff" function, which contains the code of your onConvert function. Since I had problems wih MFC classes (imcompatibilities), I´m using the libraries windef.h, and vfw.h. These are the changes in my code:
Ghraphics::TBitmap *bitmap = new Graphics::TBitmap();
...
HBITMAP hImage = (HBITMAP)LoadImage(NULL, fName, IMAGE_BITMAP,0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);
bitmap->Handle=hImage;
// Memory allocation is still 1800x1800 in your code..
BYTE* bmpBuffer=(BYTE*)GlobalAlloc(GPTR, 600*600);//allocate memory
unsigned int r;
// Size of bitmap as I draw by using x,y points...
r=GetBitmapBits(bitmap->Handle, 600*600,bmpBuffer);
//----------------------------------------------------------------------------
In BCC it says that GetBitmapBits shouldn´t be used in Win-32 applications. It would fit better in Win-16 app. But I don´t think it´s the cause of the External Exception.
I´m lost and still couldn´t find a way to solve this problem. I believe that perhaps the libtiff and their include files are causing this error. But I´m not sure at all.
If you have any clue...(I know you are not available for the momment, so I will wait for your return).
Thanks,
Letícia.
|
|
|
|
|
HBITMAP hImage = (HBITMAP)LoadImage(NULL, "mybit2.bmp", IMAGE_BITMAP,
0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);
CBitmap* m_Bitmap = CBitmap::FromHandle(hImage);
// Sumit: memory allocation is still 1800x1800 in your code..
BYTE* bmpBuffer=(BYTE*)GlobalAlloc(GPTR, 600*600);//allocate memory
// Size of bitmap as I draw by using x,y points...
m_Bitmap->GetBitmapBits(600*600 ,bmpBuffer);
TIFF *image;
// Open the TIFF file
if((image = TIFFOpen("C:\\output.tif", "w")) == NULL)
{
printf("Could not open output.tif for writing\n");
}
TIFFSetField(image, TIFFTAG_IMAGEWIDTH,600);
TIFFSetField(image, TIFFTAG_IMAGELENGTH,600);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE,1);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL,1);
uint32 rowsperstrip = TIFFDefaultStripSize(image, -1);
//<rec> gives better compression
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX3);
// TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
// TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
// Start CCITTFAX3 setting
uint32 group3options = GROUP3OPT_FILLBITS+GROUP3OPT_2DENCODING;
TIFFSetField(image, TIFFTAG_GROUP3OPTIONS, group3options);
TIFFSetField(image, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
TIFFSetField(image, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, -1L);
// End CCITTFAX3 setting
//if we comment following line then Tiff will not view in Imaging
//but view in DC
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
TIFFSetField(image, TIFFTAG_XRESOLUTION, 100.0);
TIFFSetField(image, TIFFTAG_YRESOLUTION, 100.0);
char page_number[20];
sprintf(page_number, "Page %d", 1);
TIFFSetField(image, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
TIFFSetField(image, TIFFTAG_PAGENUMBER, 1, 1);
TIFFSetField(image, TIFFTAG_PAGENAME, page_number);
// Write the information to the file
BYTE *bits;
for (int y = 0; y < 600; y++)
{
bits= bmpBuffer + y*600;
if (TIFFWriteScanline(image,bits, y, 0)==-1) MessageBox("Complete or error");
}
// Close the file
TIFFClose(image);
it's wrong,help
TIFFSetField(???)
|
|
|
|
|
Please don't mind, but I don't understand what exactly you are questioning.
This is just direction & I may have mistake, that I'm not getting time to update.
Just understand last line..
it's wrong,help
TIFFSetField(???)
If you want to ask about about this, then please check my Comment with
Mr. Ayato Kamina, just below your message.I've already tried to explain this, so please check that from that Comment.
If you still have any doubt, then please ready comment msg, you may found your answer, IF NOT?, then let me know, I may answer.
Bye
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
HI Sumit,
The above code works perfectly...
BIt where can I get the bmp to tiff in color version? is it available?
Or what change may I need to do to get it in colour?
|
|
|
|
|
Hi Leo,
Actully My requirement is to convert bmp to tiff. & In that requirement I just need to make Black & White Tiff, That I did. After that I didn't get chance to research further for it's colors version.
For the time being you can use another library available on codeproject is CXImage, you can do this task by using that library.
I'm not getting much free time for further research. As I get time,I'll update my Article.
Thanks
Sumit Kapoor
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
Hello sumit
Do have any idea on bmp to jpeg conversion, if yes plz give u r valuable hints
thanks in advance
arif
|
|
|
|
|
hi,
you can use jpeglib library for that. or there are many libraries are here in codeproject, such as CXImage etc.
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
Nice one,
Please provide a simple interface for this so that it can be easily used as a utility.
Sonork ID 100:25668 Home Page
|
|
|
|
|
Hi Manish,
If you have done c++ programming then it's too simple to make interface of this, As every thing is given here, you just need to make a function & pass parametrs of source file & target file...that's it. What more are you expecting from me, if you are doing programming then you must know to change code to function.
I hope you'll do this with just minor work.
Thanks
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
Do you have any sample about merging lots of bitmap file to a multi-page tiff file?
Thanks
|
|
|
|
|
Hi..sorry for late to reply..
What's difficult in that..You just have to repeat code between Open & Close Tiff file for no. of Tiff pages you want.
Just add one more line at the end of loop for pages:
if (Pages > 1)
{
TIFFWriteDirectory(image);
}
-------------------------------------------------------------
the overall code would look like as follow for writing iMax pages..
----------------------------------------------------
TIFF *image;
// Open the TIFF file
if((image = TIFFOpen("C:\\output.tif", "w")) == NULL)
{
printf("Could not open output.tif for writing\n");
}
for (int iPage=0;iPage<iMax;iPage++)
{
TIFFSetField(image, TIFFTAG_IMAGEWIDTH,600);
TIFFSetField(image, TIFFTAG_IMAGELENGTH,600);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE,8);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL,1);
uint32 rowsperstrip = TIFFDefaultStripSize(image, -1);
//<REC> gives better compression
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
// Start CCITTFAX3 setting
uint32 group3options = GROUP3OPT_FILLBITS+GROUP3OPT_2DENCODING;
TIFFSetField(image, TIFFTAG_GROUP3OPTIONS, group3options);
TIFFSetField(image, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
TIFFSetField(image, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, -1L);
// End CCITTFAX3 setting
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
TIFFSetField(image, TIFFTAG_XRESOLUTION, 100.0);
TIFFSetField(image, TIFFTAG_YRESOLUTION, 100.0);
char page_number[20];
sprintf(page_number, "Page %d", iPage+1);
TIFFSetField(image, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
TIFFSetField(image, TIFFTAG_PAGENUMBER, iPage+1, iPage+1);
TIFFSetField(image, TIFFTAG_PAGENAME, page_number);
// Write the information to the file
BYTE *bits;
for (int y = 0; y < 600; y++)
{
bits= bmpBuffer + y*600;
if (TIFFWriteScanline(image,bits, y, 0)==-1) MessageBox("Complete or error");
}
if (iMax > 1)
{
TIFFWriteDirectory(image);
}
} // end for of pages
// Close the file
TIFFClose(image);
////////////////////////////////////////////////////////////
That's solve..
I think my has been article updated....
Sumit
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
Yes but I have to re-open the tiff file for writing new page, that's the problem.
The first time I open using "w" mode, everything is ok, but the second time when I want to append new page, the "a" mode fail to open the existing file. Any sample ?
I'm using libtiff version 3.6
Thanks
|
|
|
|
|
I've upgraded to libtiff version 3.7 and solved my problem ! Thanks
|
|
|
|
|
zuken21,
Would you mind telling me how you read the bitmap files and converted them into a multipage tiff image? I still have some difficulties dealing with that.
I understood the code sumit worte, but the idea of reading "n" bitmap images and convert them into a multipage tiff image is confusing to me.
Thanks for your attention,
Letícia.
|
|
|
|
|
I am searching for this code too if u can find that please guide me.
Email:mohammadftm@yahoo.com
|
|
|
|
|
Hi,
I'd like to know what does the line TIFFSetField(image, TIFFTAG_GROUP3OPTIONS, group3options) do. I checked this site : http://seth.positivism.org/man.cgi/3t/TIFFSetField for the description of the TIFFSetField function but it does not tell what the 3rd parameter is. when i deleted the 3rd parameter, the code can still be compiled but I have no idea whether it runs correctly or not because whenever i try it, the program i made crashes. I found that the line above is the cause of the problem.
COuld you please tell me what the line does and what CCITTFAX3 setting ad group 3 options are? Thank you very much.
|
|
|
|
|