Solved

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

Posted on 2016-08-23
3
72 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In a previously published article (http://www.experts-exchange.com/articles/10331/Automatic-Duplex-Scanning-in-PaperPort-Versions-11-12-14.html) here at Experts Exchange, I explained how to achieve duplex (double-sided) scanning in Nuance's PaperPor…
Use email signature images to promote corporate certifications and industry awards.
Users will learn how resize a batch of photos from a single command in Photoshop via Photoshop's Image Processor. Open up an Image you'd like to resize in Adobe Photoshop: Adjust the image size according to your preferences. Image > Adjustments > â€¦
In this Micro Tutorial viewers will learn more advanced shortcuts and functions in InDesign.

749 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