| AWARE [SYSTEMS] | Imaging expertise for the Delphi developer | |||||||
![]() |
TIFF and LibTiff Mailing List Archive | |||||||
LibTiff Mailing List
TIFF and LibTiff Mailing List Archive Contact
The TIFF Mailing List Homepage |
Thread2006.08.16 02:05 "Re: How to save in tiff format file?", by Toh KcHi, Sorry to disturb again.. I have tried the method
given but still doesn't work.. I have attached 2 main
functions about saving my tiff files.
1) onSave(): opening the dialog box to save tiff file
2) SaveTiffFile(): the saving the tiff file
for the SaveTiffFile(), have already tested and able
to save a tiff file, what has really bother about ne
is still the intialisation of the array, sImg. I have
doubt here:
Can I say that for most of the time when saving the
the tiff file, the intialisation of the array for the
tiff image to save in, is the same? Thanks again for
seeing my post again. :)
void CExoDialog2Dlg::OnSave()
{
CString name1;
CFileDialog dlg(FALSE,"tif","*.tif",
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST |
OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST |
OFN_OVERWRITEPROMPT,
"TIFF Files (*.tif)|*.tif|"
"All Files (*.*)|*.*||",
NULL);
char title[]= {"Save Image"};
dlg.m_ofn.lpstrTitle= title;
if( dlg.DoModal() == IDOK )
{
CString szFile = dlg.GetFileName();
TCHAR ext[_MAX_EXT];
_tsplitpath(szFile,NULL,NULL,NULL,&ext[0]);
if(0 == _tcsicmp(ext,".tif"))
{
int nTiffPixels = TiffWidth * TiffHeight;
unsigned char *sImg = NULL;
if (sImg == NULL)
sImg = new unsigned char [nTiffPixels];
for (int i = 0; i < Gheight; i++)
for(int j = 0; j < Gwidth; j++)
sImg[i * Gwidth + j] = (unsigned char)(j * i);
name1.Format("image\\s.tif",szFile);
SaveTiffFile(name1, TiffWidth, TiffHeight, sImg);
if (sImg != NULL) delete sImg;
}
else
return;
}
void CExoDialog2Dlg::SaveTiffFile(CString szFileName,
int Width, int Height, unsigned char *Img)
{
TIFF* out;
out = TIFFOpen(szFileName, "w");
if (out != NULL)
{
uint16 compression = COMPRESSION_NONE;
uint16 photometric = PHOTOMETRIC_MINISBLACK;
short config = PLANARCONFIG_CONTIG;
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32)
Width);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32)
Height);
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric);
TIFFSetField(out, TIFFTAG_ORIENTATION,
ORIENTATION_TOPLEFT);
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(out, TIFFTAG_MINSAMPLEVALUE, 0);
TIFFSetField(out, TIFFTAG_MAXSAMPLEVALUE, 255);
TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, 1L);
TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION,
szFileName);
tdata_t buf = _TIFFmalloc(TIFFScanlineSize(out));
uint8* pp = (uint8*) buf;
long line = 0;
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x++)
pp[x] = Img[line+x];
if (TIFFWriteScanline(out, buf, Height-y-1, 0) < 0)
break;
line+=Width;
}
_TIFFfree(buf);
TIFFClose(out);
}
}
__________________________________
New and Improved Yahoo! Mail - 1GB free storage!
http://sg.whatsnew.mail.yahoo.com
|
|||||||