Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am having a requirement to print some text in a tiff file , so need help to find if windows has any feature to do such kind of thing. I am already using some third party lib to do the same but i want to see if we can do the same using windows in c# as i will be printing the same text every-time in all the tiffs. It will be very much helpful if anyone can help on this.

Thanks in Advance

What I have tried:

Used third party lib Lead tools which is working but checking for any windows methods as the requirement is just a basic thing to write some common text in the tiff file
Posted
Updated 29-Jan-19 21:25pm

1 solution

TIFF is a graphics file format, so you need to load it, get a context, draw on it, and save the result:
using (Image i = new Bitmap(@"D:\Test data\MyPic.Tif"))
    {
    using (Graphics g = Graphics.FromImage(i))
        {
        g.DrawString("Test Text", Font, Brushes.Cyan, 100, 100);
        }
    i.Save(@"D:\Test data\MyPic.Edit.tif", ImageFormat.Tiff);
    }
 
Share this answer
 
Comments
Rocky_Bas 7-Feb-19 3:15am    
Bitmap is a bit slow is there any other to do the same
Rocky_Bas 18-Feb-19 1:11am    
This is working but i have some concern here if the text is too long then the text at the end is cutting off. Is there any way if the text doesn't fit in the line then that should be printed in the next line.
OriginalGriff 18-Feb-19 2:51am    
Check the DrawString overloads - there is a version which specifies a Rectangle instead of a point.
Rocky_Bas 18-Feb-19 3:38am    
I don't want to have Rectangle
OriginalGriff 18-Feb-19 3:53am    
If you don't have a Rectangle, than you don't know where the string must end and get restarted on a new line - so even if you "brew it yourself" using MeasureString (which is pretty complicated unless you have a non-proportional font and don't care about breaks in the middle of words) you need to have that information!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900