-
DC to Tiff
Hi, I'm creating a function to convert a dc to a tiff image.
I have found libtiff, but i can't make it compile, i get an unresolved external...
Code:
Linking...
ErrHand.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
Reports.obj : error LNK2019: unresolved external symbol __imp__TIFFClose referenced in function "int __cdecl prtTiff(char *,struct HDC__ *)" (?prtTiff@@YAHPADPAUHDC__@@@Z)
Reports.obj : error LNK2019: unresolved external symbol __imp__TIFFWriteScanline referenced in function "int __cdecl prtTiff(char *,struct HDC__ *)" (?prtTiff@@YAHPADPAUHDC__@@@Z)
Reports.obj : error LNK2019: unresolved external symbol __imp__TIFFSetField referenced in function "int __cdecl prtTiff(char *,struct HDC__ *)" (?prtTiff@@YAHPADPAUHDC__@@@Z)
Reports.obj : error LNK2019: unresolved external symbol __imp__TIFFOpen referenced in function "int __cdecl prtTiff(char *,struct HDC__ *)" (?prtTiff@@YAHPADPAUHDC__@@@Z)
Also, i can't seem to get the dc converted to a bitmap to send to tibtiff, i'm using createdibsection() for this, but the bitmap returned is 0x0 pixels.
-
Is prtTiff() something you've written, or is it part of the libtiff API ?
It looks to me like you've told the compiler where the .h file is, but you haven't told the linker about the .lib file.
Project->settings->Linker->Additional libraries kind of thing
As for the dc thing, post code.
-
Got rid og the unresolved externals by copying in other versions of libtiff..
The problem now, is that the dibsection looks like it's memset to 0.. it contains only zeros..
Here's the code for the prttiff function:
Code:
int prtTiff(char *achFile, HDC dc){
DIBSECTION *hDib=0;
int res(0);
TIFF *tif;
HBITMAP hBmp;
BITMAPINFO *bmi;
//////////
UINT ilc = (GetDeviceCaps(dc,NUMCOLORS) & 0xFE);
if ((ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32) || ilc == ILC_COLOR){
VOID *bits;
if(GetDeviceCaps(dc,BITSPIXEL) <= ILC_COLOR8){
LPPALETTEENTRY pal;
ULONG i, colors;
BYTE temp;
colors = 1 << GetDeviceCaps(dc,BITSPIXEL);
bmi = (BITMAPINFO*)malloc(sizeof(BITMAPINFOHEADER)+sizeof(PALETTEENTRY)*colors);
pal = (LPPALETTEENTRY)bmi->bmiColors;
GetPaletteEntries((HPALETTE)GetStockObject(DEFAULT_PALETTE), 0, colors, pal);
/* Swap colors returned by GetPaletteEntries so we can use them for
* CreateDIBSection call. */
for (i = 0; i < colors; i++){
temp = pal[i].peBlue;
bmi->bmiColors[i].rgbRed = pal[i].peRed;
bmi->bmiColors[i].rgbBlue = temp;
}
}else{
bmi = (BITMAPINFO*)malloc(sizeof(BITMAPINFOHEADER));
}
bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi->bmiHeader.biWidth = GetDeviceCaps(dc,HORZRES);
bmi->bmiHeader.biHeight = GetDeviceCaps(dc,VERTRES);
bmi->bmiHeader.biPlanes = 1;
bmi->bmiHeader.biBitCount = GetDeviceCaps(dc,BITSPIXEL);
bmi->bmiHeader.biCompression = BI_RGB;
bmi->bmiHeader.biSizeImage = 0;
bmi->bmiHeader.biXPelsPerMeter = 0;
bmi->bmiHeader.biYPelsPerMeter = 0;
bmi->bmiHeader.biClrUsed = 0;
bmi->bmiHeader.biClrImportant = 0;
hBmp = CreateDIBSection(dc, bmi, DIB_RGB_COLORS, (void**)&hDib, 0, 0);
free(bmi);
}
//////////
// get the image information from the provided DIB
UINT32 w = hDib->dsBm.bmWidth;
UINT32 h = hDib->dsBm.bmHeight;
UINT32 total_width = hDib->dsBmih.biWidth;
UINT32 bitcount = (UINT32)hDib->dsBm.bmBits;
UINT32 bytecount = bitcount / 8;
if((w > 0) && (h > 0)){
// open the output TIFF image for writing
if((tif = TIFFOpen(achFile, "w")) == NULL)
return res;
}
// set up the image tags
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, w);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, h);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
unsigned char * psrc = (unsigned char *)hDib->dsBm.bmBits;
unsigned char * pdst = new unsigned char[(w * 3)];
UINT32 src_index;
UINT32 dst_index;
// now go line by line to write out the image data
for(UINT32 row = 0; row < h; row++ ){
// initialize the scan line to zero
memset(pdst,0,(size_t)(w * 3));
// moving the data from the dib to a row structure that
// can be used by the tiff library
for(UINT32 col = 0; col < w; col++){
src_index=(h-row-1)*total_width*bytecount+col*bytecount;
dst_index = col*3;
pdst[dst_index++]=psrc[src_index+2];
pdst[dst_index++]=psrc[src_index+1];
pdst[dst_index]=psrc[src_index];
res++;
}
// now actually write the row data
TIFFWriteScanline(tif, pdst, row, 0);
}
TIFFClose(tif);
return res;
}