Solved

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

Posted on 2016-08-23
3
79 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to escape alias names for Oracle query 1 41
async questions 5 49
Easiest intro into .NET CORE? 2 32
msiexec won't run 4 30
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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this Micro Tutorial viewers will learn more advanced shortcuts and functions in InDesign.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses

739 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