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 : Wednesday, August 4, 2010 7:45:43 AM(UTC)

Kiima  
Kiima

Groups: Registered
Posts: 25


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

 

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 : Thursday, August 5, 2010 5:46:10 AM(UTC)

Adam Boulad  
Guest

Groups: Guests
Posts: 3,028

Was thanked: 2 time(s) in 2 post(s)

The BitsPerPixel for the riPageImage (8 bits) is different from the riConvertedImage (1 bits) and this is why you are unable to use the combine method. Change the RasterImage constructor to create a 1 bit image as follows:
riPageImage.Ctor_3 RasterMemoryFlags_Conventional, 2550, 3300, 1, RasterByteOrder_Bgr, RasterViewPerspective_TopLeft
 
#3 Posted : Thursday, August 5, 2010 7:14:18 AM(UTC)

Kiima  
Kiima

Groups: Registered
Posts: 25


Thanks. That definitely fixed the issue.
 
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.146 seconds.