Using convert on .NET

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

Using convert on .NET

Post by jcasique »

Hi, I'm trying to convert TIFF image to JPG using ImageMagickObject (IM 6.4.3 Q16).

Convert from files works ok, but I want to convert a image from one memory stream to othe memory stream to update in a database, i look for the ArrayTest.vbs but it's no clear.

Does anyone has a better example?

Thank you in advance
brainlord

Re: Using convert on .NET

Post by brainlord »

I started a thread on this same topic last week. viewtopic.php?f=8&t=12073:

no real answer yet.

The example uses BLOBs not ADO streams. so it doesn't really apply.

My current workaround is to write the stream to the HD and read it back in. (a waste of time but it works)

Let me know if you figure it out
brainlord

Re: Using convert on .NET

Post by brainlord »

I GOT IT!!

Streams are a newer way to handle binary data than BLOBs.(IM uses BLOBS)
You'll have to convert by READing the stream into the array.

1st dimension the array and stream
dim myArray() as binary, mystream as stream, strPath as string

'read a file as a stream (opr get your stream some other way)
Set myStream = New Stream
strPath="c:\myfolder\myfile"
myStream.Type = adTypeBinary
MyStream.Open
myStream.LoadFromFile (strPath &".jpg")

'... (do whatever to your stream) THEN:

'(redim the array to the size of the stream)
ReDim MyArray(myStream.Size)
'and READ the stream into the array:
myStream.Position = 0
myArray = myStream.Read

'then call the IM COM Object:
strImgMsg = objMagImage.convert("jpg:", myArray, strPath & ".PNG")

'i guess you could also output to another array:
strImgMsg = objMagImage.convert("jpg:", myArray, "png:" myOtherArray)

'then you could write that array to another stream
MyOtherStream.Write MyOtherArray

'NOTE the "jpg:" parameter. that tells IMObject that the following binary array is a jpg. The ArrayTest.VBS example script uses a "null:" parameter but I could never get that to work. (IM has several filetype abbrivs: PICT, PNG, AVI etc)

not sure how you dim the size of the second array though - good luck

HTH (all code is untested)
rvanderkooy

Re: Using convert on .NET

Post by rvanderkooy »

i seem to be having some trouble with the "dim myArray() as binary" part. is that supposed to be byte and not binary? I'm looking for any simple way of working in memory using byte arrays, streams, anything other than disk. any help would be greatly appreciated. thanks in advance.
Post Reply