Page 1 of 1

run-time error

Posted: 2009-03-17T05:04:27-07:00
by allegfede
Hello, here is my piece of code:

Code: Select all

Public Function ResizeImage(Style As Integer) As Boolean
Dim OriginalX As Integer
Dim OriginalY As Integer

Dim IMG As New ImageMagickObject.MagickImage    'carica e crea l'oggetto Image Magic
Dim BMP, JPN, Result As String                  'NOTA: i file BMP devono essere in una variabile BMP e quelli JPG in una JPN

Dim DestinationRes As String

    BMP = "c:\desktop.bmp"   'existing image from a screen-capture routine
    JPN = "c:\resize.jpg"
    
    OriginalX = Screen.Width \ Screen.TwipsPerPixelX    'detect resolution of the screen-captured image
    OriginalY = Screen.Height \ Screen.TwipsPerPixelY
    
    Select Case Style      'detect the type of resize the user wishes
        Case 0  '640X480
            DestinationRes = "640X480"
        Case 1  '800x600
            DestinationRes = "800x600"
        Case 2  '1024x768
            DestinationRes = "1024x768"
        Case 3  '1280x1024
            DestinationRes = "1280x1024"
        Case 4
            DestinationRes = OriginalX & "x" & OriginalY
    End Select
    
    Result = IMG.Convert("-resize", DestinationRes, BMP, JPN)
    
    MsgBox Result
    ResizeImage = True
    
    Set IMG = Nothing
End Function
but this result in a: runtime error '-2147418113 (8000ffff)'
with this (italian) description: Metodo 'Convert' dell'oggetto 'IMagickImage' non riuscito
witch is somethin' like: 'Convert' method of object 'IMagickImage' failed (sorry for the poor traslation ;-) )

Any hint of what could happen?

PS: I'm using STATIC ImageMagic version on a Visual Basic 6 (vb6) enviroment (on win XP home machine).

PPS: This command line works great: convert -resize "800x600" c:\desktop.bmp c:\destination.jpg

Re: run-time error

Posted: 2009-03-17T05:26:24-07:00
by allegfede
I changed this line on code:

Code: Select all

    Result = IMG.Convert("-resize", """" & DestinationRes & """", BMP, JPN)
because I tought I need this string to be passed to IMAGE MAGICK "800x600", nor the simple 800x600 (withou the " character) ...

.... but no way to let it work ... still runtime error

Re: run-time error

Posted: 2009-03-17T08:27:33-07:00
by el_supremo
If I remember correctly, Basic uses the backslash as an escape character so you need to escape the backslashes in the filenames.
Try this:

Code: Select all

    BMP = "c:\\desktop.bmp"   'existing image from a screen-capture routine
    JPN = "c:\\resize.jpg"
Pete

Re: run-time error

Posted: 2009-03-18T03:37:39-07:00
by allegfede
no way.

I tryied the c:\\filename metod, but still gives an error.

Now I use to fire a shell command with short path names (before I asked user to point ImageMagick installation folder):

Code: Select all

   
    BMP = (App.Path & "\desktop.bmp")   'segna quale e' l'immagine BITMAP d'origine
    JPN = App.Path & "\resize.jpg"  'e quella JPEG finale

    Set DosFolder = FS.GetFolder(FS.GetParentFolderName(BMP))
    BMP = DosFolder.ShortPath & "\desktop.bmp"
    JPN = DosFolder.ShortPath & "\resize.jpg"
    
    Set DosFolder = FS.GetFolder(FS.GetParentFolderName(IM_Path))
    IM_Path = DosFolder.ShortPath & "\convert.exe"
    
    Shell IM_Path & " -resize """ & DestinationRes & """ " & BMP & " " & JPN, vbMinimizedFocus

no one have a more elegant way?

Do I need to install ImaeMagic even if I use the DLL on my apps?

Thanks