J
Jeff Gress
Thanks to help from a few people this very economical
amount of code creates a copy of a tif images, writes
data to it and saves as with a new name. It does almost
everything I want it to do and in an acceptable amount of
time.
My problem is that the resulting TIF image is not saved
as a black and white, grayscaled image, but with colors
and I don't know how to turn this off. Also the
resulting tif comes out to over 100K instead of around 10-
15K.
If I overload the bitmap.Save method with
System.Drawing.Imaging.ImageFormat.Tiff not only does the
size jump to nearly 350K, but I then end up with a TIF
image that requires LZW compression instead of the Group
IV TIF I want.
I have seen examples that use unsafe code to accomplish
this, but the example is slower than I'd like and is
several hundreds of lines of code when it seems to me
like I should be able to add a line or two of code to the
following dozen or so lines I have and be done.
What am I missing?
Thanks,
Jeff Gress
private Font textFont;
private FontFamily serifFontFamily;
serifFontFamily = new FontFamily
(GenericFontFamilies.Serif);
textFont = new Font(serifFontFamily, 24);
string textToDraw;
Image image = Image.FromFile(@"c:\apps\amod2.tif");
Bitmap bitmap = new Bitmap(image);
Graphics g = Graphics.FromImage(bitmap);
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
g.PixelOffsetMode =
System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
textToDraw = "Welcome back my friend";
g.DrawString(textToDraw, textFont, new SolidBrush
(Color.Black), 184, 342);
// Set the resolution and save the bitmap object
bitmap.SetResolution(200,200);
bitmap.Save(@"c:\apps\amod3.tif");
amount of code creates a copy of a tif images, writes
data to it and saves as with a new name. It does almost
everything I want it to do and in an acceptable amount of
time.
My problem is that the resulting TIF image is not saved
as a black and white, grayscaled image, but with colors
and I don't know how to turn this off. Also the
resulting tif comes out to over 100K instead of around 10-
15K.
If I overload the bitmap.Save method with
System.Drawing.Imaging.ImageFormat.Tiff not only does the
size jump to nearly 350K, but I then end up with a TIF
image that requires LZW compression instead of the Group
IV TIF I want.
I have seen examples that use unsafe code to accomplish
this, but the example is slower than I'd like and is
several hundreds of lines of code when it seems to me
like I should be able to add a line or two of code to the
following dozen or so lines I have and be done.
What am I missing?
Thanks,
Jeff Gress
private Font textFont;
private FontFamily serifFontFamily;
serifFontFamily = new FontFamily
(GenericFontFamilies.Serif);
textFont = new Font(serifFontFamily, 24);
string textToDraw;
Image image = Image.FromFile(@"c:\apps\amod2.tif");
Bitmap bitmap = new Bitmap(image);
Graphics g = Graphics.FromImage(bitmap);
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
g.PixelOffsetMode =
System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
textToDraw = "Welcome back my friend";
g.DrawString(textToDraw, textFont, new SolidBrush
(Color.Black), 184, 342);
// Set the resolution and save the bitmap object
bitmap.SetResolution(200,200);
bitmap.Save(@"c:\apps\amod3.tif");