Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Do you know how to write a C# function to create a .TIF image file ?

Posted on 2016-08-23
3
Medium Priority
?
108 Views
Last Modified: 2016-08-24
I am writing a C# application using VS2010 and .Net Framwork 4.0.

Do you know how to write a C# function to create a .TIF image file that contains the statement:   Image Not Available

 As for the properties of the .TIF image file, preferably it would have a width of about 1700 pixels and a height of about 650 pixels.

 You can look at the attached ImageNotAvailable.docx for the properties of another .TIF image file I am also working with.
0
Comment
Question by:zimmer9
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
Kyaw Wanna earned 2000 total points
ID: 41768062
Hello,

It should need to create the bitmap file or convert to bitmap, first.
And then convert to tiff.

Create bitmap file
Please refer to this url https://msdn.microsoft.com/en-us/library/6c7eyzyb.aspx

Convert to BitMap File

Bitmap bitmap = (Bitmap)Image.FromFile(file);

Open in new window


 Convert from Bitmap to Memory stream
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);

Open in new window


Convert from MemoryStream to Tif

Image tiff = Image.FromStream(byteStream)

ImageCodecInfo encoderInfo = GetEncoderInfo("image/tiff");

EncoderParameters encoderParams = new EncoderParameters(2);
EncoderParameter parameter = new EncoderParameter(
    Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = parameter;
parameter = new EncoderParameter(Encoder.SaveFlag, 
    (long)EncoderValue.MultiFrame);
encoderParams.Param[1] = parameter;

tiff.Save(sOutFilePath, encoderInfo, encoderParams);

Open in new window

0
 

Author Comment

by:zimmer9
ID: 41768655
Why is the text not centered in the following code?

How can the following code be modified to center the text?

            Bitmap bmp = new Bitmap(1024, 512);
            using (Graphics graph = Graphics.FromImage(bmp))
            {
                Rectangle ImageSize = new Rectangle(0, 0, 1024, 1024);
                StringFormat sf = new StringFormat();
                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment = StringAlignment.Center;

                graph.FillRectangle(Brushes.White, ImageSize);
                graph.DrawString("IMAGE NOT AVAILABLE", new Font("Tahoma", 50), Brushes.Black, ImageSize, sf);
               
            }

            bmp.Save(TARGET_DIR_IN + "_Blank.TIF");
0
 

Author Comment

by:zimmer9
ID: 41768665
Rectangle ImageSize = new Rectangle(0, 0, 1024, 1024);

I used the wrong value   s/b      

 Rectangle ImageSize = new Rectangle(0, 0, 1024, 512);
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to convert a multi-page PDF file into multiple image files, with one image file created for each page of the PDF. It does this by utilizing an excellent, free software package called GraphicsMagick. The solution is amazingly s…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this Micro Tutorial viewers will learn more advanced shortcuts and functions in InDesign.
The goal of the tutorial is to teach the user how to use the cropping tool and to straighten there photos so it does not look tilted. You will choose which photo you want to edit, crop it to you liking and make it straight.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question