Solved

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

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The goal of the tutorial is to teach the user how to import photos into Adobe Lightroom efficiently and to keep everything organized.
The goal of the tutorial is to teach the user how to remove a natural vignette your photos and how to add vignette to your photos.

630 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