Berry Tsakala
Berry Tsakala

Reputation: 16600

using imagemagick convert from visual basic .net

how should be the proper run imagemagick convert function in VB.NET ?

i've tried naming explicitly each argument

    Public Magick As ImageMagickObject.MagickImage

    Dim s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11 As String

    If IsDBNull(FromImage) Then s1 = "" Else s1 = CStr(FromImage)
    If IsDBNull(Rotate1) Then s2 = "" Else s2 = CStr(FromImage)
    If IsDBNull(Rotate2) Then s3 = "" Else s3 = CStr(FromImage)
    If IsDBNull(Resize1) Then s4 = "" Else s4 = CStr(FromImage)
    If IsDBNull(Resize2) Then s5 = "" Else s5 = CStr(FromImage)
    If IsDBNull(Extra_Imagemagick_settings) Then s6 = "" Else s6 = CStr(FromImage)
    If IsDBNull(Alpha1) Then s7 = "" Else s7 = CStr(FromImage)
    If IsDBNull(Alpha2) Then s8 = "" Else s8 = CStr(FromImage)
    If IsDBNull(Alpha3) Then s9 = "" Else s9 = CStr(FromImage)
    If IsDBNull(Alpha4) Then s10 = "" Else s10 = CStr(FromImage)
    If IsDBNull(ToImage) Then s11 = "" Else s11 = CStr(FromImage)
    Dim params As String() = {s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11}
    Magick.Convert(params)

i tried creating an array:

    Dim params As object() = {FromImage, Rotate1, Rotate2, Resize1, Resize2, Extra_Imagemagick_settings, Alpha1, Alpha2, Alpha3, Alpha4, ToImage}

    params = New Object()
    ReDim params(20)
    params(0) = CStr(FromImage)
    params(1) = Rotate1
    params(2) = Rotate2
    params(3) = Resize1
    params(4) = Resize2
    params(5) = Extra_Imagemagick_settings
    params(6) = Alpha1
    params(7) = Alpha2
    params(8) = Alpha3
    params(9) = Alpha4
    params(10) = ToImage
    Magick.Convert(params)

I tried to feed "convert()" directory with the arguments:

    Magick.Convert(FromImage, Rotate1, Rotate2, Resize1, Resize2, Extra_Imagemagick_settings, Alpha1, Alpha2, Alpha3, Alpha4, ToImage)

every time i have a different exception, usually:

Object reference not set to an instance of an object.

or

Use the New keyword to create the instance.

(it's probably because of me being new to DOT NET)

Upvotes: 0

Views: 3903

Answers (1)

Berry Tsakala
Berry Tsakala

Reputation: 16600

The main problem was 32/64 bit.

I didn't manage to make it work in 100% 64bit (but i didn't try too hard, either).

  1. create a project.
  2. if you're using the "vb express" version, you have to manually edit the *.vbproj file and add this line x86 after each section that mentions CPU (there's TONS of posts about it in the inernet).
  3. this example was taken from http://www.imagemagick.org/discourse-server/viewtopic.php?f=8&t=13295 and it was the first one to work for me (i simplified it).

    Dim img As ImageMagickObject.MagickImage
    img = New ImageMagickObject.MagickImage
    MSGS = img.Convert("C:\a.bmp", "-resize", "x128", "C:\a.jpg")
    img = Nothing
    

Upvotes: 2

Related Questions