Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, October 12, 2006 6:05:27 AM(UTC)
garrettgoehner

Groups: Registered
Posts: 2


In case there is an easier way of doing this with LEAD tools that I am ignorant too, I’ll explain my setup and what I am looking to do.

 

I have a web application that allows a user to search a library of tif files.  The resulting search page then displays a file link for them to open the tif using whatever application launches on their machine that is associated with .tif files.

 

What I’d like to do is give them the option to view them in the browser by converting them to .jpg files.  Some, but not all of the files are multi page .tifs and that’s where I am having trouble.

 

I am new to LEAD tools and am having a hard time finding the correct component to get me started.

 

After thinking about it, maybe it would be better if single page .tifs where converted to JPG for display in the browser and multipage .tifs were converted to PDF's. 

 

If you can point me in the right direction for .tif -> jpg and multipage .tif -> .pdf, i'd be able to figure it out from there.  I prefer to use .net 2.0 framwork with vb.net.

 

 

Thanks,

Garrett Goehner

 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Friday, October 13, 2006 7:11:28 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


This VB.NET code shows how to load a Multipage TIF (4 pages) and save it into 4 separate JPEG files.

'Load the image
img = codecs.Load(Application.StartupPath + "\..\combined.TIF", 0, CodecsLoadByteOrder.BgrOrGray, 1, 4)

'Save each page as a separate file.  You might prefer to do a loop, but for the sake of example,
'I've hard coded it.
codecs.Save(img, Application.StartupPath + "\..\1.jpg", RasterImageFormat.Jpeg, 24, 1, 1, 1, CodecsSavePageMode.Overwrite)
codecs.Save(img, Application.StartupPath + "\..\2.jpg", RasterImageFormat.Jpeg, 24, 2, 2, 1, CodecsSavePageMode.Overwrite)
codecs.Save(img, Application.StartupPath + "\..\3.jpg", RasterImageFormat.Jpeg, 24, 3, 3, 1, CodecsSavePageMode.Overwrite)
codecs.Save(img, Application.StartupPath + "\..\4.jpg", RasterImageFormat.Jpeg, 24, 4, 4, 1, CodecsSavePageMode.Overwrite)

If you want to save all the pages of a file to a single PDF, you would use this line of code:
codecs.Save(img, Application.StartupPath + "\..\combinedOUT.pdf", RasterImageFormat.RasPdf, 24, 1, 4, 1, CodecsSavePageMode.Overwrite)
 
#3 Posted : Wednesday, October 18, 2006 6:56:43 AM(UTC)
garrettgoehner

Groups: Registered
Posts: 2


Thanks for the quick response.  I was able to build on your example above to do exactly what I was looking for.

I am having some issues with being able to save the jpeg with higher compression.  Saving a single (black and white) page from the multipage tiff results in a ~265kb jpg.  Using codecs.Options.Jpeg.Save.QualityFactor (1 - 255) doesn't seem to make much of a difference in the end size of the file.  I have searched the documentation as well as google looking for better options/examples and can't seem to find anything.

        Dim codecs As New Leadtools.Codecs.RasterCodecs
        codecs.Options.Jpeg.Save.QualityFactor = 255
        codecs.Options.Jpeg.Save.Passes = 1
        Dim tifToJPG As Leadtools.RasterImage
        tifToJPG = codecs.Load("C:\Temp\tifs\1-page.tif", 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
        codecs.Save(tifToJPG, "C:\Temp\tifs\test.jpg", RasterImageFormat.Jpeg, 8, 1, 1, 1, CodecsSavePageMode.Overwrite)

Thanks again,

Garrett

 
#4 Posted : Friday, October 20, 2006 11:14:00 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


I just did a simple test with similar code and my output files had a significant difference in file size.  The file with qfactor = 255 was 9kb and my file with qfactor = 2 was 49kb.  Here's the code I used:

codecs.Options.Jpeg.Save.Passes = 1
img = codecs.Load(Application.StartupPath + "\..\1.tif")
codecs.Options.Jpeg.Save.QualityFactor = 2
codecs.Save(img, Application.StartupPath + "\..\out_2.jpg", RasterImageFormat.Jpeg, 8, 1, 1, 1, CodecsSavePageMode.Overwrite)
codecs.Options.Jpeg.Save.QualityFactor = 255
codecs.Save(img, Application.StartupPath + "\..\out_255.jpg", RasterImageFormat.Jpeg, 8, 1, 1, 1, CodecsSavePageMode.Overwrite))

I've also attached the source file I used and the two resulting files for you to look at.  It could be something with the file you are using, compression algorithms will not always give the same ratios between file sizes for each source file.  If you want I could take a look at the source file(s) you are having trouble with and see what I can do.
File Attachment(s):
images.zip (57kb) downloaded 128 time(s).
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.118 seconds.