Return-Path: <tiff-bounces@lists.maptools.org>
Received: from mailgate103.isp.belgacom.be (mailgate103.isp.belgacom.be [195.238.6.84])
        by inmx011.isp.belgacom.be (8.12.11.20060308/8.12.11/Skynet-IN-2.32) with ESMTP id l3BD4QIB024744
        for <joris.at.lebbeke@skynet.be>; Wed, 11 Apr 2007 15:04:31 +0200
        (envelope-from <tiff-bounces@lists.maptools.org>)
Received: from r153.dmsolutions.ca (HELO duke.maptools.org) ([209.217.116.153])
  by in.mx.skynet.be with ESMTP; 11 Apr 2007 15:04:26 +0200
Received: from duke.maptools.org (duke.maptools.org [127.0.0.1])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id l3BCpPgQ016997;
	Wed, 11 Apr 2007 08:52:32 -0400
Received: from mail.modulnet.com (mail.modulnet.com [217.8.156.102])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id l3BCpMrl016993
	for <tiff@lists.maptools.org>; Wed, 11 Apr 2007 08:51:23 -0400
Received: from ksosiemens by modulnet.com (MDaemon PRO v9.5.4)
	with ESMTP id md50002133608.msg
	for <tiff@lists.maptools.org>; Wed, 11 Apr 2007 14:50:00 +0200
From: <sirkukskall@yahoo.no>
To: <tiff@lists.maptools.org>
Date: Wed, 11 Apr 2007 14:49:31 +0200
Message-ID: <001c01c77c37$d98f2130$0301a8c0@ksosiemens>
MIME-Version: 1.0
X-Mailer: Microsoft Office Outlook 11
Thread-Index: Acd8N9jCJYPFKMGHQLWj4Z6RqFgS3A==
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
X-Authenticated-Sender: koverli@datadesign.no
X-Spam-Processed: modulnet.com, Wed, 11 Apr 2007 14:50:00 +0200
	(not processed: message from valid local sender)
X-MDRemoteIP: 62.176.197.242
X-Return-Path: knut@datadesign.no
X-Envelope-From: knut@datadesign.no
X-MDaemon-Deliver-To: tiff@lists.maptools.org
X-MDAV-Processed: modulnet.com, Wed, 11 Apr 2007 14:50:02 +0200
Subject: [Tiff] DC to tiff
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.4
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Content-Type: multipart/mixed; boundary="===============0374247316=="
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org
X-UIDL: 000000000023ceae.000022e1
X-MSP-STORE: Wed, 11 Apr 2007 15:04:32 +0200
Status:   

This is a multi-part message in MIME format.

--===============0374247316==
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_001D_01C77C48.9D17F130"

This is a multi-part message in MIME format.

------=_NextPart_000_001D_01C77C48.9D17F130
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Anybody know how to print a DC to a tiff file? I can't seem to make it
work..
 
Code:
BITMAPINFOHEADER *pBMh = NULL;
BITMAPINFO *pBM = NULL;
BYTE *bits;
HBITMAP hBmp;
TIFF *tif;
// Allocate bitmap info header 
pBMh =
(BITMAPINFOHEADER*)malloc(sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD));
if(pBMh == NULL){
return 0;
}

memset(pBMh, 0, sizeof(BITMAPINFOHEADER));
pBMh->biSize = sizeof(BITMAPINFOHEADER);
pBMh->biHeight = GetDeviceCaps(dc, VERTRES);
pBMh->biWidth = ((((int)GetDeviceCaps(dc, HORZRES)*8)+31)&~31)>>3;
pBMh->biBitCount = 24;
pBMh->biPlanes = 1;
pBMh->biCompression = BI_RGB;
// Setup color table for mono DIBs
pBM = (BITMAPINFO*)pBMh;
pBM->bmiColors[1].rgbBlue = 255;
pBM->bmiColors[1].rgbGreen = 255;
pBM->bmiColors[1].rgbRed = 255;
hBmp = CreateDIBSection(dc, (BITMAPINFO*)pBMh, DIB_RGB_COLORS,
(void**)&bits, 0, 0);
if(!hBmp || !bits){
free(pBMh);
return(0);
}

// get the image information from the provided DIB
UINT32 height = pBMh->biHeight;
UINT32 width = pBMh->biWidth;
UINT32 bitcount = (UINT32)pBMh->biBitCount;
UINT32 bytecount = bitcount / 8;
free(pBMh);
if((width > 0) && (height > 0)){
// open the output TIFF image for writing
if((tif = TIFFOpen(achFile, "w")) == NULL)
return 0;
}

// set up the image tags

TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);

TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);

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 *)bits;

unsigned char * pdst = new unsigned char[(width * 3)];

UINT32 src_index=0;

UINT32 dst_index=0;

// now go line by line to write out the image data

for(UINT32 row = 0; row < height; row++ ){

// initialize the scan line to zero

memset(pdst,0,(size_t)(width * 3));

// moving the data from the dib to a row structure that

// can be used by the tiff library

for(UINT32 col = 0; col < (UINT32)width; col++){

src_index=(width-row-1)*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];

}

// now actually write the row data

TIFFWriteScanline(tif, pdst, row, 0);

}

TIFFClose(tif);

return 1;

 

------=_NextPart_000_001D_01C77C48.9D17F130
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16414" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D530124512-11042007>A</SPAN><SPAN=20
class=3D530124512-11042007>nybody know how to print a DC to a tiff file? =
I can't=20
seem to make it work..</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
class=3D530124512-11042007></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
class=3D530124512-11042007>Code:</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D530124512-11042007><FONT size=3D2>
<P>BITMAPINFOHEADER *pBMh =3D NULL;<BR>BITMAPINFO *pBM =3D NULL;<BR>BYTE =

*bits;<BR>HBITMAP hBmp;<BR>TIFF *tif;<BR></FONT><FONT color=3D#008000 =
size=3D2>//=20
Allocate bitmap info header <BR></FONT><FONT size=3D2>pBMh =3D=20
(BITMAPINFOHEADER*)malloc(</FONT><FONT color=3D#0000ff =
size=3D2>sizeof</FONT><FONT=20
size=3D2>(BITMAPINFOHEADER)+256*</FONT><FONT color=3D#0000ff=20
size=3D2>sizeof</FONT><FONT size=3D2>(RGBQUAD));<BR></FONT><FONT =
color=3D#0000ff=20
size=3D2>if</FONT><FONT size=3D2>(pBMh =3D=3D NULL){<BR></FONT><FONT =
color=3D#0000ff=20
size=3D2>return</FONT><FONT size=3D2> 0;<BR>}</P>
<P>memset(pBMh, 0, </FONT><FONT color=3D#0000ff =
size=3D2>sizeof</FONT><FONT=20
size=3D2>(BITMAPINFOHEADER));<BR>pBMh-&gt;biSize =3D </FONT><FONT =
color=3D#0000ff=20
size=3D2>sizeof</FONT><FONT =
size=3D2>(BITMAPINFOHEADER);<BR>pBMh-&gt;biHeight =3D=20
GetDeviceCaps(dc, VERTRES);<BR>pBMh-&gt;biWidth =3D ((((</FONT><FONT =
color=3D#0000ff=20
size=3D2>int</FONT><FONT size=3D2>)GetDeviceCaps(dc,=20
HORZRES)*8)+31)&amp;~31)&gt;&gt;3;<BR>pBMh-&gt;biBitCount =3D=20
24;<BR>pBMh-&gt;biPlanes =3D 1;<BR>pBMh-&gt;biCompression =3D=20
BI_RGB;<BR></FONT><FONT color=3D#008000 size=3D2>// Setup color table =
for mono=20
DIBs<BR></FONT><FONT size=3D2>pBM =3D=20
(BITMAPINFO*)pBMh;<BR>pBM-&gt;bmiColors[1].rgbBlue =3D=20
255;<BR>pBM-&gt;bmiColors[1].rgbGreen =3D =
255;<BR>pBM-&gt;bmiColors[1].rgbRed =3D=20
255;<BR>hBmp =3D CreateDIBSection(dc, (BITMAPINFO*)pBMh, DIB_RGB_COLORS, =

(</FONT><FONT color=3D#0000ff size=3D2>void</FONT><FONT =
size=3D2>**)&amp;bits, 0,=20
0);<BR></FONT><FONT color=3D#0000ff size=3D2>if</FONT><FONT =
size=3D2>(!hBmp ||=20
!bits){<BR>free(pBMh);<BR></FONT><FONT color=3D#0000ff =
size=3D2>return</FONT><FONT=20
size=3D2>(0);<BR>}<BR><BR></FONT><FONT color=3D#008000 size=3D2>// get =
the image=20
information from the provided DIB<BR></FONT><FONT size=3D2>UINT32 height =
=3D=20
pBMh-&gt;biHeight;<BR>UINT32 width =3D pBMh-&gt;biWidth;<BR>UINT32 =
bitcount =3D=20
(UINT32)pBMh-&gt;biBitCount;<BR>UINT32 bytecount =3D bitcount /=20
8;<BR>free(pBMh);<BR></FONT><FONT color=3D#0000ff =
size=3D2>if</FONT><FONT=20
size=3D2>((width &gt; 0) &amp;&amp; (height &gt; 0)){<BR></FONT><FONT=20
color=3D#008000 size=3D2>// open the output TIFF image for =
writing<BR></FONT><FONT=20
color=3D#0000ff size=3D2>if</FONT><FONT size=3D2>((tif =3D =
TIFFOpen(achFile,=20
</FONT><FONT color=3D#a31515 size=3D2>"w"</FONT><FONT size=3D2>)) =3D=3D =

NULL)<BR></FONT><FONT color=3D#0000ff size=3D2>return</FONT><FONT =
size=3D2>=20
0;<BR>}</P>
<P></FONT><FONT color=3D#008000 size=3D2>// set up the image =
tags</P></FONT><FONT=20
size=3D2>
<P>TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);</P>
<P>TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);</P>
<P>TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);</P>
<P>TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);</P>
<P>TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);</P>
<P>TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);</P>
<P>TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1);</P>
<P>TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);</P>
<P>TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE);</P>
<P>TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);</P>
<P></FONT><FONT color=3D#0000ff size=3D2>unsigned</FONT><FONT size=3D2> =
</FONT><FONT=20
color=3D#0000ff size=3D2>char</FONT><FONT size=3D2> * psrc =3D =
(</FONT><FONT=20
color=3D#0000ff size=3D2>unsigned</FONT><FONT size=3D2> </FONT><FONT =
color=3D#0000ff=20
size=3D2>char</FONT><FONT size=3D2> *)bits;</P>
<P></FONT><FONT color=3D#0000ff size=3D2>unsigned</FONT><FONT size=3D2> =
</FONT><FONT=20
color=3D#0000ff size=3D2>char</FONT><FONT size=3D2> * pdst =3D =
</FONT><FONT=20
color=3D#0000ff size=3D2>new</FONT><FONT size=3D2> </FONT><FONT =
color=3D#0000ff=20
size=3D2>unsigned</FONT><FONT size=3D2> </FONT><FONT color=3D#0000ff=20
size=3D2>char</FONT><FONT size=3D2>[(width * 3)];</P>
<P>UINT32 src_index=3D0;</P>
<P>UINT32 dst_index=3D0;</P>
<P></FONT><FONT color=3D#008000 size=3D2>// now go line by line to write =
out the=20
image data</P></FONT><FONT size=3D2>
<P></FONT><FONT color=3D#0000ff size=3D2>for</FONT><FONT =
size=3D2>(UINT32 row =3D 0; row=20
&lt; height; row++ ){</P>
<P></FONT><FONT color=3D#008000 size=3D2>// initialize the scan line to=20
zero</P></FONT><FONT size=3D2>
<P>memset(pdst,0,(size_t)(width * 3));</P>
<P></FONT><FONT color=3D#008000 size=3D2>// moving the data from the dib =
to a row=20
structure that</P></FONT><FONT size=3D2>
<P></FONT><FONT color=3D#008000 size=3D2>// can be used by the tiff=20
library</P></FONT><FONT size=3D2>
<P></FONT><FONT color=3D#0000ff size=3D2>for</FONT><FONT =
size=3D2>(UINT32 col =3D 0; col=20
&lt; (UINT32)width; col++){</P>
<P>src_index=3D(width-row-1)*width*bytecount+col*bytecount;</P>
<P>dst_index =3D col*3;</P>
<P>pdst[dst_index++]=3Dpsrc[src_index+2];</P>
<P>pdst[dst_index++]=3Dpsrc[src_index+1];</P>
<P>pdst[dst_index]=3Dpsrc[src_index];</P>
<P>}</P>
<P></FONT><FONT color=3D#008000 size=3D2>// now actually write the row=20
data</P></FONT><FONT size=3D2>
<P>TIFFWriteScanline(tif, pdst, row, 0);</P>
<P>}</P>
<P>TIFFClose(tif);</P>
<P></FONT><FONT color=3D#0000ff size=3D2>return</FONT><FONT size=3D2>=20
1;</P></FONT>&nbsp;</SPAN></FONT></FONT></DIV></BODY></HTML>

------=_NextPart_000_001D_01C77C48.9D17F130--


--===============0374247316==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
--===============0374247316==--
