Conversion of an array of images into a single image...

ImageMagickObject is a Windows COM+ interface to ImageMagick. COM+, Visual Basic, and Delphi users should post to this discussion group.
Post Reply
Nantallen

Conversion of an array of images into a single image...

Post by Nantallen » 2009-02-24T15:25:18-07:00

Hello Everyone.

I apologize if this has been covered elsewhere on the forums. I have not been able to locate info pertaining to my issue and am stumped.

I am accessing a directory via System.IO in a VB.net application that returns an array of the filenames of all TIFFs in said directory. I can convert those TIFFs to single PDFs with no issue, but I'd like to give the users the option to merge them under a single PDF. Unfortunately, I either get an exception or a null return. Ex.:

Code: Select all

Dim imo as ImageMagickObject.MagickImage
Dim filelist As String
Dim result As String

If merge_tif = True Then
	filelist = ""
	For Each file As FileInfo In Files
		filelist = filelist & "," & file.fullname
		System.Threading.Thread.Sleep(1000)
	Next
	filelist = filelist.TrimStart(",")
	imo = CreateObject("Imagemagickobject.MagickImage.1")
	result = imo.Convert(filelist,dest_dir & "\" & merge_file & ".pdf")
	imo = Nothing
Else
From my last run:
  • filelist = "C:\TIF2PDF\file1.tif,C:\TIF2PDF\file2.tif"
    dest_dir & "\" & merge_file & ".pdf" = "C:\TIF2PDF\merged.pdf"
All variables are cast prior to the IF statement (dest_dir and merge_file are strings populated with values on the form that calls this Sub).

I am quite a beginner at this, so any help would be greatly appreciated. Also, if anyone has any good links on Exception Handling for the COM object, I could definitely use that too.

Nantallen

Re: Conversion of an array of images into a single image...

Post by Nantallen » 2009-02-26T06:51:29-07:00

Through trial and error, I figured out my error. I was trying to pass a string which was not being parsed correctly by the object. Instead, I passed all arguments into an object-typed (replacement casting for variant) array, then passed the array to the Object for conversion.

Code: Select all

				If merge_tif = True Then
					Dim merge_commands() As object
					Dim i As Integer
					
					i = 0

					Array.Resize(merge_commands,files.GetUpperBound(0) + 3)

					For Each file As FileInfo In Files
						merge_commands(i) = file.FullName
						i = i+1
						System.Threading.Thread.Sleep(1000)
					Next
					merge_commands(i) = "-append"
					merge_commands(i+1) = dest_dir & "\" & merge_file & ".pdf"

					imo = CreateObject("Imagemagickobject.MagickImage.1")
					result = imo.Convert(merge_commands)
					imo = Nothing
I realize this is still very ugly to most professional programmers, but as I mentioned before, I am just beginning. So any links or tips that could be provided to make this cleaner or more efficient would be greatly appreciated.

Post Reply