Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create .tif file from SQL data 1

Status
Not open for further replies.

RichS

Programmer
Apr 24, 2000
380
US
I am trying to create a .tif file, in memory, from data retrieved from an SQL database. (This .tif file will be faxed to the Internet users fax machine.)

I've looked at the System.Graphics API. It seems to have a lot to do with manipulating graphical shapes so I am not sure if this API is where I should be looking. All I need is the text involved in sort of a report format.

Does anyone know how to do this?
Thanks.
 
Check out the System.Drawing namespaces which provides an API to use GDI+; You can create a tiff something like
Code:
Bitmap bitmap = new Bitmap(width, height);
//Create your graphic. this is where you use System.Graphics
Bitmap.Save(Stream, ImageFormat.Tiff);
Im not to fly with creating the grpahic so you'll have to google for that but there are plenty of articles out there on dynamically creating images using C#.

Rob

Every gun that is made, every warship launched, every rocket fired, signifies in the final sense a theft from those who hunger and are not fed, those who are cold and are not clothed - Eisenhower 1953
 
Thanks Rob,
If anyone else is interested, the following is my first attempt at this that worked. (Credit also: John O'Donnell for the basic code at "
Code:
using System.Drawing;  // Reference System.Drawing.dll API
using System.Drawing.Imaging;

.....

        internal string CreateTiff(
            int width, 
            int height, 
            string font, 
            string color, 
            string bcolor)
        {
            // The data to be displayed
            string strTitle = "Department of Human Services\nChild Care Billing\n\n";
            string strHeader = "Warrant No\tDate\tAmount\n\n";
            string strBody = "here is my data";

            // Set the location of the peices of data
            PointF pTitle = new PointF( 1.0F, 1.0F );
            PointF pHeader = new PointF( 1.0F, 60.0F );
            PointF pBody = new PointF( 1.0F, 75.0F );

            SolidBrush brush = new SolidBrush(Color.FromName(color));
            Bitmap bm = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(bm);

            g.Clear(Color.FromName(bcolor));
            
            // Set the font for each data section
            Font fTitle = new Font( font, 12, System.Drawing.FontStyle.Bold );
            Font fHeader = new Font( font, 10, System.Drawing.FontStyle.Underline );
            Font fBody = new Font( font, 10, System.Drawing.FontStyle.Regular );
            
            // Draw the text
            g.DrawString( strTitle, fTitle, brush, pTitle );
            g.DrawString( strHeader, fHeader, brush, pHeader );
            g.DrawString( strBody, fBody, brush, pBody );

            // Save the file as a .tiff
            bm.Save(@"C:\aTiffTest\MyTiff.tiff", ImageFormat.Tiff);
            return "Success";

        }

Rich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top