|
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.
|
|
|
|
|
Hi again,
I think i've figured out what the line does. I think that the third parameter is the value you want to set for the image right? if that's correct then what does the line :
uint32 group3options = GROUP3OPT_FILLBITS+GROUP3OPT_2DENCODING; do?
I know that TIFFTAG_GROUP3OPTIONS is a 32 bit flag, while the GROUP3OPT_FILLBITS is supposed to fill to byte boundary and GROUP3OPT_2DENCODING means 2d decoding. but i still don't understand what does the line do.
Also, it will be helpful if you could tell me where i can find a site which explains what TIFF is all about. Thank you very much.
|
|
|
|
|
Hi Dear,
I think you must make button or small dialog or window ever in your application. If No! then suppose you need to draw rectangle in your application....Then what..
If are going to draw any object(button or rectangle), then what's must thing for it?
That's properties..such as Width, Height, Color, Border..etc. you can't draw object without using it's properties....
Same thing is happening in this code..when we need to make Tiff file then we first define it's properties.(How can you fill a rectangle when you don't know where is border of that rectangle?)
what TIFFSetField() is doing? It is setting properties of Tiff file.
Suppose you have to set Image width then what would you do.
you would use a single function TIFFSetField()..
How?...
TIFFSetField( Source_Image, Property_I_want_to_set, Property_Value)
means like this...
TIFFSetField(image, TIFFTAG_IMAGEWIDTH,600);
same for Height of image..Like this...
TIFFSetField(image, TIFFTAG_IMAGELENGTH,600);
Read property tag as TIFF TAG_IMAGE LENGTH =>TIFFTAG_IMAGELENGTH
There are hundreds of properties that can be set for Tiff file..
For all properties & their meaning please Open file "Tiff.h".
You asked about CCITTFAX3...
This is standard for making tiff file that can be used for Fax like devices.
That's solve..I think Now don't have any doubt..
OK! Good Bye..Keep Smile
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
okay, I think i get the idea roughly now. Thanks for going through the trouble to explain it to me. That's very kind of you. Thanks again for the help.
|
|
|
|
|
Hi Friends,
If you finding such a problem then that may be your editior problem, How that is interpreting following setting.
e.g: I've a image that show black screen in one editor but fine in other editor.
By the way, If you are facing sach a problem just change setting as given follow.
First)--------->
--------------------------------->
There are multiple types of PHOTOMETRIC, You can see by just find "PHOTOMETRIC" in your project that would give #define PHOTOMETRIC......
These are types of PHOTOMETRIC, But I'm only using two type..
1. PHOTOMETRIC_MINISWHITE /* min value is white */
2. PHOTOMETRIC_MINISBLACK /* min value is black */
You can change these values as per required in Your image by changing setting in
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
Second)------->
--------------------------------->
There are two fill Order that can affact Image.
1. FILLORDER_MSB2LSB
2. FILLORDER_LSB2MSB
You can change this value in following line & test on your image whichever is suit to your image.
FFSetField(image, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB);
OK! Good Bye..Enjoy.
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
Hye,
I have a tiff image and want to crop some part of tiff image for further processing... Say I want to remove upper 1 inch of image and save other image as another TIFF image... Since my source and destination image format is TIFF, is it possible to do this with libTIFF???
If this is possible and if you have some handy code to do this, please send me that... Thanks..
Jigar Mehta
(jigarmehta@gatescorp.com)
Software Developer
Gates Information Systems
|
|
|
|
|
Hi..Jigar,
I've never try this type of work with Libtiff, As I get free time I'll try to do.
One tip for you. By using that u can do this task.
1. Convert Tiff to bitmap.
2. Split bitmap . (You can read this article for this: http://www.codeproject.com/bitmap/bitmap.asp )
3. then again convert that Bitmap to Tiff file.
OK! Good bye
Never consider anything Impossible before trying to solve that..---Sumit Kapoor--- sumit.kapoor@pecint.com
|
|
|
|
|
I have created a Bitmap Object using this...
Image image(L"myImage.bmp");
Now I want to convert this in to EPS File .How do I do this?.please help me....
|
|
|
|
|
HI Dear...
Sorry Dear, but I don't know how to convert bitmap to EPS in program..ya some software such as Adobe Photoshop etc. give facility to convert BMP to EPS..
But I think u r finding change through Program...
SO SORRY I Can't help U.. But I'll try to convert or to arrange some helpful code..
OK! Good Bye...
Never consider anything Impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
This sample code works fine for desktop but doesnt work fine for wince devices because of limitation of the APIs supported like GetBitmapBits().
Do u have any workaround for this?
|
|
|
|
|
hi..Sorry..
I don't have any idea for WIN CE..
sorry I can't help u in this regard..
Thanks for reading this...
Bye
Never consider anything Impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|