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, January 28, 2010 9:34:56 AM(UTC)

Kiima  
Kiima

Groups: Registered
Posts: 25


Hi,
  I'm having some issues converting a jpg type to a reasonable looking TIF. If I use a different image printer (Image001-OtherSoftware), I can get the image to look and physically print nicely. However, using the leadtools code the image looks horribly pixelated. What am I missing?

Attached are the sample files. Notice that I've tried LeadTools in both 100 and 600 resolutions.

    Public Shared Function ConvertJPGtoTIF(ByVal strImageFile As String) As String
        RasterCodecs.Startup()
        Dim codecs As New RasterCodecs, mDPI As Integer = 600

        'converting file
        Dim riConvertedImageFile As RasterImage = codecs.Load(strImageFile)
        codecs.Save(riConvertedImageFile, strConvertedJPGFilePath, RasterImageFormat.CcittGroup4, 0)
        riConvertedImageFile.Dispose()
        riConvertedImageFile = Nothing

        GC.Collect()                            'manually collection garbage, so the memory does not run out on large PDFs
        GC.WaitForPendingFinalizers()
        GC.Collect()
        GC.WaitForPendingFinalizers()

        RasterCodecs.Shutdown()
        Return strConvertedJPGFilePath
    End Function


-Kiima
LeadTools 16.5
WinForm VB.NET
File Attachment(s):
Conversion.zip (82kb) downloaded 21 time(s).
 

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, January 29, 2010 6:28:34 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


The problem is that you're not taking control over the conversion from 24bpp color to 1bpp black and white.  RasterCodecs.Save will do some default conversions and usually just goes for the fastest method rather than the highest quality.  Use the ColorResolutionCommand to convert the image to 1bpp and specifying the desired flags for resampling the image data.

The other software appears to be some kind of print to file appliation.  It is upsizing the image based on the DPI you provided so it has more data to work with.  The RasterImage.XResolution and YResolution properties simply describe the image data.  You must proportionally resize the image data with the SizeCommand as well if you want it to be 600 DPI with the same print size.

Here's an example and I've attached the resulting image:


' load original file
Dim riConvertedImageFile As RasterImage = codecs.Load(Application.StartupPath + "\..\..\..\image001.jpg")

' proportionally resize to 600 DPI
Dim mDPI As Integer = 600
Dim cmdSize As New SizeCommand()
cmdSize.Flags = RasterSizeFlags.Bicubic
cmdSize.Width = riConvertedImageFile.Width * (mDPI / riConvertedImageFile.XResolution)
cmdSize.Height = riConvertedImageFile.Height * (mDPI / riConvertedImageFile.YResolution)
cmdSize.Run(riConvertedImageFile)

' Set DPI
riConvertedImageFile.XResolution = mDPI
riConvertedImageFile.YResolution = mDPI

' convert to 1bpp
Dim cmdColorRes As New ColorResolutionCommand()
cmdColorRes.BitsPerPixel = 1
cmdColorRes.Colors = 2
cmdColorRes.DitheringMethod = RasterDitheringMethod.FloydStein
cmdColorRes.Mode = ColorResolutionCommandMode.InPlace
cmdColorRes.Order = RasterByteOrder.Bgr
cmdColorRes.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed
cmdColorRes.Run(riConvertedImageFile)

'save the image
codecs.Save(riConvertedImageFile, Application.StartupPath + "\..\..\..\out.tif", RasterImageFormat.CcittGroup4, 0)

File Attachment(s):
out.tif (320kb) downloaded 19 time(s).
 
#3 Posted : Friday, January 29, 2010 7:24:36 AM(UTC)

Kiima  
Kiima

Groups: Registered
Posts: 25


Thanks so much! That's exactly what I was looking for. I had tried the SizeCommand, but was missing the ColorResolutionCommand.

Thanks again,
   -Kiima
 
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-2020, Yet Another Forum.NET
This page was generated in 0.059 seconds.