-1

I'm writing tif Files in C#.

CODE:

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(800, 1000); //Creates Bitmap
using(Graphics g = Graphics.FromImage(bitmap))
 {
    RectangleF rect = new RectangleF(new PointF(0, 700), new SizeF(200,200)); 
    StringFormat drawFormat = new StringFormat();
    drawFormat.Alignment = StringAlignment.Near;
    g.DrawString("Comment: " + CommentBox.Text, outputFont, Brushes.Black, rect, drawFormat); }

However a 3rd party application is having difficult viewing these tif files. I can navigate directly to the repository where these files are saved and open them for viewing.

My C# tif files that aren't viewable by the 3rd party software have a Bit depth = 32 and Compression of '' (guessing this is the default)

tif files that are viewable by the 3rd party software (and not created by my C# code) have a Bit depth = 1 and Compression = 'CCITT T.6'

Can anyone explain to me what the difference is, and possibly why my file is not viewable by the 3rd party software?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Philo
  • 1,931
  • 12
  • 39
  • 77
  • 1
    No where in that code do you create a TIFF image. Show us how you are encoding the image. – Ed S. Jan 11 '14 at 00:04
  • ok. filename = savedirectory + id + counter + '.tif' – Philo Jan 11 '14 at 00:07
  • That creates a string, it does not save an image. – Ed S. Jan 11 '14 at 00:20
  • bitmap.Save(fileName); – Philo Jan 11 '14 at 00:24
  • That will save the image as bmp, not tiff. You have to specify the file format also, it's not derived from the file extension. – Guffa Jan 11 '14 at 00:26
  • My files are being saved as tif files (checked it from file property). Is there a way I can specify the file format instead of delving into the conversion code? – Philo Jan 11 '14 at 00:29
  • 1
    The file type information in the file properties is only based on the file extension, not on what the file actually contains. You specify the file format when you save the image: `bitmap.Save(fileName, ImageFormat.Tiff);`. – Guffa Jan 11 '14 at 18:18
  • thanks. But I still can't get the 3rd party app to open my tiff file. The compression is :LZW, I would like it to be CCITT T.6. Is there a way to set it while original file is being saved? – Philo Jan 14 '14 at 23:16
  • @Guffa I solved that part but am having a new issue with the CCITT compression technique, the entire image is coming out as a solid black background:- http://stackoverflow.com/questions/21192691/c-after-applying-ccitt-compression-on-my-tiff-file-it-produces-an-image-with – Philo Jan 17 '14 at 18:50

1 Answers1

2

The difference between the images is that the one that you create from C# is an uncompressed color image with three 8-bit color channels (RGB) and an 8-bit alpha channel, while the 3rd party software uses monochrome fax images. Most likely the software isn't capable to open full color images.

The answers here should help you to create a monochrome image, then the 3rd party software might be able to open it: Converting a bitmap to monochrome

Community
  • 1
  • 1
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • Is there a way to save my file formatted directly into Tiff monochrome instead of bitmap or using this conversion method? – Philo Jan 11 '14 at 16:56