Hi,
I am trying to convert, resize and insert a jpg into a TIF Group 4 image that is size: 8.5(2550) by 11(3300) with 300 DPI. That said, I expect there to be a lot of white space. I also need a 1 inch border around the jpg. It's important that I don't distort it. What is the best (quality and time) way to do this?
Code below.
The conversion part works for me, but the combine command errors (Invalid parameter passed) on the run command. What am I missing?
-Kiima
LeadTools 16.5 (have latest dlls)
VB6, WinForms, COM Interop
Dim codecs As New RasterCodecs, riConvertedImage As New RasterImage, riPageImage As New RasterImage
Dim rasterCmd As New RasterCommand
On Error GoTo LeadToolsError
codecs.Startup
'Loading image
Set riConvertedImage = codecs.Load_12(mstrPathAndFileName)
Dim origDPI As Integer
origDPI = riConvertedImage.XResolution
Dim destDPI As Integer
destDPI = 300
If origDPI <> 300 Then
'Proportionally resize to 300 DPI (for good quality that looks like grayscale)
Dim cmdsize As New SizeCommand
cmdsize.Flags = RasterSizeFlags_Bicubic
cmdsize.Width = CInt(riConvertedImage.Width * (destDPI / riConvertedImage.XResolution))
cmdsize.Height = CInt(riConvertedImage.Height * (destDPI / riConvertedImage.YResolution))
rasterCmd.Run cmdsize, riConvertedImage
'Set DPI
riConvertedImage.XResolution = destDPI
riConvertedImage.YResolution = destDPI
End If
'Convert to 1bpp (for good quality that looks like grayscale)
Dim cmdColorRes As New ColorResolutionCommand
cmdColorRes.BitsPerPixel = 1
cmdColorRes.DitheringMethod = RasterDitheringMethod_Stucki
cmdColorRes.Mode = ColorResolutionCommandMode_InPlace
cmdColorRes.Order = RasterByteOrder_Bgr
cmdColorRes.PaletteFlags = ColorResolutionCommandPaletteFlags_Fixed
cmdColorRes.Run riConvertedImage
'Resize to fit on 1 page
Dim cmdsize1 As New SizeCommand
cmdsize1.Ctor 1950, 2700, RasterSizeFlags_Bicubic
rasterCmd.Run cmdsize1, riConvertedImage
'Create a new 8.5 x 11 page
riPageImage.Ctor_3 RasterMemoryFlags_Conventional, 2550, 3300, 0, RasterByteOrder_Bgr, RasterViewPerspective_TopLeft
riPageImage.XResolution = destDPI
riPageImage.YResolution = destDPI
'Fill the image with white color
Dim fill As New FillCommand
Dim rc As New RasterColor
rc.Ctor_3 255, 255, 255
fill.Ctor rc
rasterCmd.Run fill, riPageImage
'Combine the original image, offset by a border of 1
Dim combine As New CombineFastCommand
Dim rect As New LTDInterop16.Rectangle
rect.x = destDPI
rect.y = destDPI
rect.Width = riConvertedImage.Width
rect.Height = riConvertedImage.Height
Dim p As New LTDInterop16.Point
p.x = 0
p.y = 0
combine.Ctor riPageImage, rect, p, CombineFastCommandFlags_SourceCopy
rasterCmd.Run combine, riConvertedImage
'Save the image
codecs.Save_6 riPageImage, mstrFilenameOutput, RasterImageFormat_CcittGroup4, 0
mintPageCount = riPageImage.PageCount
riPageImage.Dispose
riConvertedImage.Dispose
Set riPageImage = Nothing
Set riConvertedImage = Nothing
codecs.Shutdown
Set codecs = Nothing
Exit Sub