Click here to Skip to main content
15,893,814 members
Articles / Web Development / ASP.NET

ImageMagick in VB.NET

Rate me:
Please Sign up or sign in to vote.
4.78/5 (27 votes)
22 May 200722 min read 418.4K   32.9K   137  
ImageMagick is a powerful image manipulation that supports a wide variety of formats. In this article we develop an ImageMagick Wraper in C++ to expose functionalities in Magick++ to a .NET application.
<?xml version="1.0"?>
<!DOCTYPE delegatemap [
  <!ELEMENT delegatemap (delegate+)>
  <!ELEMENT delegate (#PCDATA)>
  <!ATTLIST delegate decode CDATA #IMPLIED>
  <!ATTLIST delegate encode CDATA #IMPLIED>
  <!ATTLIST delegate mode CDATA #IMPLIED>
  <!ATTLIST delegate spawn CDATA #IMPLIED>
  <!ATTLIST delegate stealth CDATA #IMPLIED>
  <!ATTLIST delegate command CDATA #REQUIRED>
]>
<!--
  Delegate command file.

  Commands which specify

    decode="in_format" encode="out_format"

  specify the rules for converting from in_format to out_format These
  rules may be used to translate directly between formats.

  Commands which specify only

    decode="in_format"

  specify the rules for converting from in_format to some format that
  ImageMagick will automatically recognize. These rules are used to
  decode formats.

  Commands which specify only

   encode="out_format"

  specify the rules for an "encoder" which may accept any input format.

  For delegates other than ps:alpha, ps:color, ps:mono, and mpeg-encode the
  substitution rules are as follows:

    %i  input image filename
    %o  output image filename
    %u  unique temporary filename
    %z  secondary unique temporary filename

    %#  input image signature
    %b  image file size
    %c  input image comment
    %g  window group
    %h  image rows (height)
    %k  input image number colors
    %m  input image format
    %p  page number
    %q  input image depth
    "%s"  scene number
    %w  image columns (width)
    %x  input image x resolution
    %y  input image y resolution

-->
<delegatemap>
<delegate decode="autotrace" stealth="True" command='autotrace -output-format svg -output-file "%o" "%i"' />
  <delegate decode="bmp" encode="launch" mode="encode" command='imdisplay.exe "%i."' />
  <delegate decode="bmp" encode="win" mode="encode" command='imdisplay.exe "%i."' />
  <delegate decode="browse" restrain="True" spawn="True" command='cmd /C start http://www.imagemagick.org/'  />
  <delegate decode="cgm" command='ralcgm -d ps "%i" "%o" "%u"
    convert -concatenate %o*.ps "%o"' />
  <delegate decode="compress" restrain="True" command='|uncompress -c "%i"' />
  <delegate decode="cr2" thread-support="False" command='dcraw.exe -T -w -O "%o" "%i"' />
  <delegate decode="crw" thread-support="False" command='dcraw.exe -T -w -O "%o" "%i"' />
  <delegate decode="dcr" thread-support="False" command='dcraw.exe -T -w -O "%o" "%i"' />
  <delegate decode="dng" thread-support="False" command='dcraw.exe -T -w -O "%o" "%i"' />
  <delegate decode="nrw" thread-support="False" command='dcraw.exe -T -w -O "%o" "%i"' />
  <delegate decode="orf" thread-support="False" command='dcraw.exe -T -w -O "%o" "%i"' />
  <delegate decode="raf" thread-support="False" command='dcraw.exe -T -w -O "%o" "%i"' />
  <delegate decode="x3f" thread-support="False" command='dcraw.exe -T -w -O "%o" "%i"' />
  <delegate decode="dot" command='dot -Tps "%i" -o "%o"' />
  <delegate decode="dvi" command='dvips -q -o "%o" "%i"' />
  <delegate decode="edit" restrain="True" command='notepad "%o"' />
  <delegate decode="eps" encode="pdf" mode="bi" command='"@PSDelegate@" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dEPSCrop -dAlignToPixels=0 -sDEVICE=pdfwrite "-sOutputFile=%o" -- "%i"' />
  <delegate decode="eps" encode="ps" mode="bi" command='"@PSDelegate@" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dEPSCrop -dAlignToPixels=0 -sDEVICE=pswrite "-sOutputFile=%o" -- "%i"' />
  <delegate decode="fig" command='/usr/X11R6/bin/fig2dev -L ps "%i" "%o"' />
  <delegate decode="gplt" command='/bin/echo "set size 1.25,0.62
    set terminal postscript portrait color solid; set output "%o"; load "%i"" &gt; "%u";gnuplot %u' />
  <delegate decode="ps:alpha" restrain="True" command='"@PSDelegate@" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-g%s" "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"' />
  <delegate decode="ps:color" restrain="True" command='"@PSDelegate@" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-g%s" "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"' />
  <delegate decode="ps:cmyk" restrain="True" command='"@PSDelegate@" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 "-sDEVICE=bmpsep8" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-g%s" "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"' />
  <delegate decode="ps:mono" restrain="True" command='"@PSDelegate@" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-g%s" "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"' />
  <delegate decode="hpg" command='hp2xx -q -m eps -f "%o" "%i"' />
  <delegate decode="hpgl" command='hp2xx -q -m eps -f "%o" "%i"' />
  <delegate decode="htm" command='html2ps -U -o "%o" "%i"' />
  <delegate decode="html" command='html2ps -U -o "%o" "%i"' />
  <delegate decode="ilbm" command='ilbmtoppm "%i" &gt; "%o"' />
  <delegate decode="man" command='groff -man -Tps "%i" &gt; "%o"' />
  <delegate decode="mpeg-decode" stealth="True" command='mpeg2dec.exe -q -b "%i" -f -r -o3 "%u%%d"' />
  <delegate encode="mpeg-encode" stealth="True" command='mpeg2enc.exe "%i" "%o"' />
  <delegate decode="pcl-color" restrain="True" command='"pcl6.exe" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-g%s" "-r%s" %s "-sOutputFile=%s" "%s"' />
  <delegate decode="pcl-cmyk" restrain="True" command='"pcl6.exe" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 "-sDEVICE=bmpsep8" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-g%s" "-r%s" %s "-sOutputFile=%s" "%s"' />
  <delegate decode="pcl-mono" restrain="True" command='"pcl6.exe" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 "-sDEVICE=pbmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-g%s" "-r%s" %s "-sOutputFile=%s" "%s"' />
  <delegate decode="pdf" encode="eps" mode="bi" command='"@PSDelegate@" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -sDEVICE=epswrite "-sOutputFile=%o" -- "%i"' />
  <delegate decode="pdf" encode="ps" mode="bi" command='"@PSDelegate@" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -sDEVICE=pswrite "-sOutputFile=%o" -- "%i"' />
  <delegate decode="pgp" command='pgpv -fq "%i"' />
  <delegate decode="pnm" encode="ilbm" mode="encode" command='ppmtoilbm -24if "%i" &gt; "%o"' />
  <delegate decode="pov" command='povray "+i"%i"" -D0 +o"%o" +fn%q +w%w +h%h +a -q9 -kfi"%s" -kff"%n"
    convert -concatenate %o*.png "%o"' />
  <delegate decode="ps" encode="eps" mode="bi" command='"@PSDelegate@" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -sDEVICE=epswrite "-sOutputFile=%o" -- "%i"' />
  <delegate decode="ps" encode="pdf" mode="bi" command='"@PSDelegate@" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -sDEVICE=pdfwrite "-sOutputFile=%o" -- "%i"' />
  <delegate decode="rad" command='ra_ppm -g 1.0 "%i" "%o"' />
  <delegate decode="rgba" encode="rle" mode="encode" command='pnmtorle -o "%o" -v "%i"' />
  <delegate decode="scan" command='scanimage -d "%i" &gt; "%o"' />
  <delegate decode="shtml" command='html2ps -U -o "%o" "%i"' />
  <delegate decode="txt" encode="ps" mode="bi" command='enscript -o "%o" "%i"' />
  <delegate decode="xcf" command='xcftopnm "%i" &gt; "%o"' />
  <delegate encode="compress" restrain="True" command='|compress -c &gt; "%o"' />
  <delegate encode="show" restrain="True" spawn="True" command='imdisplay.exe -immutable -window_group %g -title "%l of %f" "tmp:%o"' />
</delegatemap>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Singapore Singapore
bubble2k is a software architect in an IT consulting firm. He does in his free time recreational development with C# and Flash, for games, multimedia, and emulation. He also does web and digital graphics design.

Dubble Design
I Want More Money, I Need More Money

Comments and Discussions