Im trying to pull up an existing TIF, add text to it and then save it with a new filename. Ive using part of the Microsft GDIPlus sample as a jumping off point.
I define a brush called backgroundBrush and a bitmap called backgroundImage so the following lines:
backgroundImage = new Bitmap(@"c:\apps\amod.tif");
backgroundBrush = new TextureBrush(backgroundImage);
uses my tif template as a brush that gets painted to the entire client area in the OnPaint method when I do the following:
g.FillRectangle(backgroundBrush, ClientRectangle);
I then add code in the OnPaint method to write text to the "screen"? Im so confused.
string textToDraw="John Smith";
g.DrawString(textToDraw, textFont, new SolidBrush(Color.Black), 184, 342);
textToDraw="Something Else";
g.DrawString(textToDraw, textFont, new SolidBrush(Color.Black), 236, 390);
Finally I try to save it:
backgroundImage.Save(@"c:\apps\saveamod.tif");
The text does not save, only the bitmap.
I understand why this happens, I just dont know what to do about it. Truthfully Id rather not see the image at all, Id just like to create it and save it and be done with it. This is going to be written to run in a batch process mode and It will be data-driven rather than the hard-coded example here. Im worried that once I figure out how to save the text with the image as a new file Ill have to completely rewrite it to do this without it being displayed on the screen.
Any help would be appreciated.
Thank you,
Jeff Gress
Heres the entire code (its short):
public class TextSample : Form
{
private System.ComponentModel.Container components;
private Brush backgroundBrush;
private Font textFont;
private FontFamily serifFontFamily;
public static Image backgroundImage;
public TextSample()
{
InitializeComponent();
serifFontFamily = new FontFamily (GenericFontFamilies.Serif);
this.SetStyle(ControlStyles.ResizeRedraw,true);
backgroundImage = new Bitmap(@"c:\apps\amod.tif");
//Now create the brush we are going to use to paint the background
backgroundBrush = new TextureBrush(backgroundImage);
textFont = new Font(serifFontFamily, 24);
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
g.FillRectangle(backgroundBrush, ClientRectangle);
string textToDraw="John Smith";
g.DrawString(textToDraw, textFont, new SolidBrush(Color.Black), 184, 342);
textToDraw="General Motors";
g.DrawString(textToDraw, textFont, new SolidBrush(Color.Black), 236, 390);
backgroundImage.Save(@"c:\apps\saveamod.tif");
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container ();
this.Size = new System.Drawing.Size(800,640);
this.Text = "Test Application";
}
[STAThread]
public static void Main()
{
Application.Run(new TextSample());
}
}
I define a brush called backgroundBrush and a bitmap called backgroundImage so the following lines:
backgroundImage = new Bitmap(@"c:\apps\amod.tif");
backgroundBrush = new TextureBrush(backgroundImage);
uses my tif template as a brush that gets painted to the entire client area in the OnPaint method when I do the following:
g.FillRectangle(backgroundBrush, ClientRectangle);
I then add code in the OnPaint method to write text to the "screen"? Im so confused.
string textToDraw="John Smith";
g.DrawString(textToDraw, textFont, new SolidBrush(Color.Black), 184, 342);
textToDraw="Something Else";
g.DrawString(textToDraw, textFont, new SolidBrush(Color.Black), 236, 390);
Finally I try to save it:
backgroundImage.Save(@"c:\apps\saveamod.tif");
The text does not save, only the bitmap.
I understand why this happens, I just dont know what to do about it. Truthfully Id rather not see the image at all, Id just like to create it and save it and be done with it. This is going to be written to run in a batch process mode and It will be data-driven rather than the hard-coded example here. Im worried that once I figure out how to save the text with the image as a new file Ill have to completely rewrite it to do this without it being displayed on the screen.
Any help would be appreciated.
Thank you,
Jeff Gress
Heres the entire code (its short):
public class TextSample : Form
{
private System.ComponentModel.Container components;
private Brush backgroundBrush;
private Font textFont;
private FontFamily serifFontFamily;
public static Image backgroundImage;
public TextSample()
{
InitializeComponent();
serifFontFamily = new FontFamily (GenericFontFamilies.Serif);
this.SetStyle(ControlStyles.ResizeRedraw,true);
backgroundImage = new Bitmap(@"c:\apps\amod.tif");
//Now create the brush we are going to use to paint the background
backgroundBrush = new TextureBrush(backgroundImage);
textFont = new Font(serifFontFamily, 24);
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
g.FillRectangle(backgroundBrush, ClientRectangle);
string textToDraw="John Smith";
g.DrawString(textToDraw, textFont, new SolidBrush(Color.Black), 184, 342);
textToDraw="General Motors";
g.DrawString(textToDraw, textFont, new SolidBrush(Color.Black), 236, 390);
backgroundImage.Save(@"c:\apps\saveamod.tif");
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container ();
this.Size = new System.Drawing.Size(800,640);
this.Text = "Test Application";
}
[STAThread]
public static void Main()
{
Application.Run(new TextSample());
}
}