?
Solved

Create Tiff Image

Posted on 2014-04-24
16
Medium Priority
?
602 Views
Last Modified: 2014-04-28
Good afternoon Experts!

OK, so I need to create a TIFF Image...BUT it needs to be in the same compression as another TIFF Image I have from a system I'm using.  I want to create my own TIFF Images for this system...but the ones I've created using VB.net 2005 have not been in the same format as the ones on this system.

So my question is how can I determine what compression the TIFF file is I have so I can try to replicate it in the same format.

Thanks,
Mark
0
Comment
Question by:smithmrk
[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
  • 7
  • 6
  • 3
16 Comments
 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 400 total points
ID: 40021159
If you open it in Irfanview ( http://www.irfanview.com/ ) and press I, an information window will pop up and tell you what compression is being used.
0
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40021165
Hi Mark,
I have this C# code in my files from a few years ago (it should not be difficult for you to convert it to VB.Net):
public static int GetCompressionType(Image image)
{
  int compressionTagIndex = Array.IndexOf(image.PropertyIdList, 0x103);
  PropertyItem compressionTag = image.PropertyItems[compressionTagIndex];
  return BitConverter.ToInt16(compressionTag.Value, 0);
}

Open in new window

I normally like to attribute sources, but in this case I don't show it in my records. The return value is supposed to be the compression method, but you should check this through some experimentation:

1=None
2=Huffman
3=ITU-T (formerly CCITT) Group 3
4=ITU-T (formerly CCITT) Group 4
5=LZW

To test the above, you can use IrfanView (free) to create TIFF files with various compression:
http://www.irfanview.com/

The IrfanView GUI gives you a dialog box where you have a radio button to select compression, while the IrfanView command line (i_view32.exe) has this option:

/tifc=N

where N is defined as:

0=None
1=LZW
2=Packbits
3=ITU-T (formerly CCITT) Group 3
4=ITU-T (formerly CCITT) Group 4
5=Huffman
6=JPG
7=ZIP

Also, the IrfanView GUI will show the TIFF compression via the Image menu then Information (or the blue circle "i" icon on the toolbar):

IrfanView showing TIFF compressionRegards, Joe
0
 

Author Comment

by:smithmrk
ID: 40021227
AWESOME!!!!

OK, It was created in CCITT Group 4 Fax Encoding, how can I create images in VB.net in this same format?

Thanks,
Mark
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40021317
Well, an easy way to do it is run the command line IrfanView with the "/tifc=4" parameter from your VB.Net program. The IrfanView call would be something like this:

i_view32.exe /multitif=(convertedG4.tif,input.tif) /killmesoftly /silent /tifc=4

The command line syntax, with all of the options and many examples, is in a plain text file called <i_options.txt> that is placed in the installation folder. Btw, IrfanView does not have to be "installed" to run it. Of course, it doesn't hurt to do a standard install (which will put the files in <Program Files> or <Program Files (x86)>), but all that you need for the command line to work is access to <i_view32.exe> and <i_view32.ini> (the latter is IrfanView's configuration file).

If you'd like to see a call to IrfanView with the "/tifc" parameter from a program (although not VB.Net), take a look at this article:
http://www.experts-exchange.com/Web_Development/Document_Imaging/A_10745-How-To-Combine-Merge-Append-TIFF-Files-in-Batch-Mode.html

It's a long article and a somewhat large program, but you can focus just on the RunWait call to IrfanView. Regards, Joe
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40021321
You need to check your own images.  There are at least 8 different compression methods shown in Irfanview when you do a "Save As" to TIFF.
0
 

Author Comment

by:smithmrk
ID: 40021344
Seems like a lot of work...is there any way I can take this code shown here and save it as that Compression Type?

'Image Information:
        Dim ImgOffset As Int32 = 0
        Dim ImgLength As Int32 = 0
        Dim ImgResolution As Int32 = 200
        Dim ImgHeight As Int32 = 574
        Dim ImgWidth As Int32 = 1312

        Dim ImageWriter As IO.FileStream = New IO.FileStream("C:\TestImage.tif", FileMode.Create)
        Dim memstrm As IO.MemoryStream = New IO.MemoryStream
        Dim ticket As New Bitmap(ImgWidth, ImgHeight)

        'Fonts:
        Dim BatchID_Font As New Font("Arial", 20, FontStyle.Regular)
        Dim BatchAuthor_Font As New Font("Arial", 15, FontStyle.Regular)

        Dim ticketGraphics As Graphics = Graphics.FromImage(ticket)
        ticketGraphics.FillRectangle(Brushes.White, 0, 0, ImgWidth, ImgHeight)
        ticket.SetResolution(ImgResolution, ImgResolution)

        ticketGraphics.DrawString("-- My Ticket --", BatchID_Font, Brushes.Black, 520, 90)
        ticketGraphics.DrawString("Ticket ID: 800001", BatchID_Font, Brushes.Black, 10, 160)
        ticketGraphics.DrawString("Ticket Amount: 111", BatchID_Font, Brushes.Black, 10, 200)
        ticketGraphics.DrawString("Date: " & Now().ToShortDateString, BatchID_Font, Brushes.Black, 10, 240)

        ticket.Save(memstrm, System.Drawing.Imaging.ImageFormat.Tiff)
        memstrm.WriteTo(ImageWriter)
        ImgLength = memstrm.Length

        ticket.Dispose()
        Logo.Dispose()
        memstrm.Close()
        memstrm.Dispose()
0
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40021353
> There are at least 8 different compression methods shown in Irfanview when you do a "Save As" to TIFF.

Yes, those 8 compression methods are described in post <http:#a40021165> above for the command line call (/tifc=0 through /tifc=7). For the GUI, the 8 methods are chosen with radio buttons like this:

IrfanView GUI showing TIFF compressionRegards, Joe
0
 

Author Comment

by:smithmrk
ID: 40021363
Thanks but I don't want to use different program I want to create my own images in CCITT Group 4 Format out of my own program.

Mark
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40021375
I was just asking if you had checked your own images.
0
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40021379
> Seems like a lot of work

It should be just one line of code...maybe a few if VB.Net needs some kind of setup to run an EXE. I don't code in VB.Net, but there must be a way to run an EXE file, so it should be something like this:

whatever.calls.an.EXE.in.VB.Net i_view32.exe /multitif=(convertedG4.tif,input.tif) /killmesoftly /silent /tifc=4

Since I don't know VB.Net, I can't help with the code you posted. I'm sure Dave can (he's a real expert in .NET) or maybe someone else will jump in to look at your code. Regards, Joe
0
 

Author Comment

by:smithmrk
ID: 40021402
What I meant by it being a lot of work is that I don't want a 3rd party application (I_View32.exe) to have to be installed on the users machine.

I found this by I get Paramater Not Valid error can someone tell me why I get that when I select the CompressionCCITT4?

http://msdn.microsoft.com/en-us/library/system.drawing.imaging.encoder.compression(v=vs.80).aspx

Thanks,
Mark
0
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40021426
Mark,
Here's the VB link showing the choices for EncoderValue:
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.encodervalue%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

It says that the one you're looking for is:

CompressionCCITT4

If that's not working, I don't know why.

Btw, you do not have to install IrfanView on the user's machine. Put it on a server...wherever you're putting your program...all you have to do is put <i_view32.exe> and <i_view32.ini> in the same folder as your program.

I need to leave my office now for a couple of hours. I'll check back into this thread to see how you're doing as soon as I return. Regards, Joe
0
 

Author Comment

by:smithmrk
ID: 40021535
OK, this worked...
i_view32.exe /multitif=(convertedG4.tif,input.tif) /killmesoftly /silent /tifc=4

Now I have a NEW Problem!
I need to merge several images into one TIFF File, how can I do that?

You see I'm creating these images with my program vitural tickets...once done I need them in one file with offsets.

For example:
File = MyImageFile.tif

1st Image = offset 0 size = 1459
2nd Image = offset 1459 size 1536
3rd Image = offset 2995 size 1544
4th Image = offset 4539 size 1389
etc...

Because the receiving application of this TIFF Image File is looking to pick up these images within this one file based on the offset and size of the image.

Thanks,
Mark
0
 
LVL 56

Accepted Solution

by:
Joe Winograd, EE MVE 2015&2016 earned 1600 total points
ID: 40021613
Great...glad to hear that worked!

IrfanView lets you combine multiple TIFFs into a single, multi-page TIFF, but it does not give you control over the offsets. The syntax to combine multiple TIFFs is to put as many file names as you want after the first file name (which is the output file). For example:

i_view32.exe /multitif=(out.tif,in1.tif,in2.tif,in3.tif) /killmesoftly /silent /tifc=4

Also, it supports wildcards:

i_view32.exe /multitif=(out.tif,in*.tif) /killmesoftly /silent /tifc=4

And you can do both at once (multiple files and wildcards):

i_view32.exe /multitif=(out.tif,in1.tif,source*.tif,in2.tif) /killmesoftly /silent /tifc=4

We had a thread a few months ago where the asker wanted to combine multiple TIFFs into a single TIFF based on a starting position number (aka an offset) and a length. Perhaps you'll find it helpful:

http://www.experts-exchange.com/Software/Misc/Q_28332667.html

Regards, Joe
0
 

Author Closing Comment

by:smithmrk
ID: 40027294
Thanks Guys!

Joe that link to the other issue someone was having REALLY HELPED!!!!

Thanks,
Mark
0
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40027384
Mark,
You're very welcome. That is certainly a brilliant piece of code that kaufmed wrote and I'm glad that it helped you. Regards, Joe
0

Featured Post

Independent Software Vendors: 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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 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