FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ImageMagick and Juno

 
Post new topic   Reply to topic     Forum Index -> Juno
View previous topic :: View next topic  
Author Message
yidabu



Joined: 21 Apr 2007
Posts: 87

PostPosted: Wed Aug 01, 2007 3:49 pm    Post subject: ImageMagick and Juno Reply with quote

ImageMagick and Juno


Download ImageMagick from:
http://www.imagemagick.org/script/binary-releases.php#windows
http://www.imagemagick.org/download/binaries/ImageMagick-6.3.5-4-Q16-windows-static.exe
install it with ole support.

late binding example (works fine):
Code:
   auto im = new DispatchObject("ImageMagickObject.MagickImage");   
   im.call("Convert", "D:\\old.jpg", "D:\\new.gif");



How to use early binding with ImageMagick by juno?

Here is some introdution of ImageMagick Object:
http://www.imagemagick.org/script/ImageMagickObject.php

My code:

Code:
   IMagickImage im = MagickImage.coCreate!(IMagickImage)(ExecutionContext.InProcessServer);
   assert(im, "failed im");
   scope(exit) tryRelease(im);
   string[] args = ["D:\\old.JPG", "D:\\new.gif"];
   SAFEARRAY* pa = toSafeArray(args);
   VARIANT v;
   auto hr =im.Convert(*pa, v);
   writefln("result 0x", hr);// result is -2147215503


What problem with it ? and how to fix it ?



some information;
run
Quote:
tlbimpd ImageMagickObject.dll /comments
to get typle library:

Quote:
// ImageMagickObject 1.0 Type Library
// Version 1.0

/*[uuid("9aa0fc6a-63c7-3632-bd6b-7caf646e51a0")]*/
module ydb.com.imagemagickobject;

/*[importlib("stdole2.tlb")]*/
private import juno.com.core;

// Interfaces

// IMagickImage Interface
interface IMagickImage : IDispatch {
/*[uuid("7f670536-00ae-4edf-b06f-13bd22b25624")]*/
static GUID IID = { 0x7f670536, 0x00ae, 0x4edf, 0xb0, 0x6f, 0x13, 0xbd, 0x22, 0xb2, 0x56, 0x24 };
/*[id(0x60020000)]*/ int OnStartPage(IUnknown piUnk);
/*[id(0x60020001)]*/ int OnEndPage();
/*[id(0x00000001)]*/ int get_Count(out int pVal);
/*[id(0x00000002)]*/ int Add(ref SAFEARRAY pArrayVar, out VARIANT pVar);
/*[id(0x00000003)]*/ int Remove(VARIANT varIndex);
/*[id(0x00000004)]*/ int Compare(ref SAFEARRAY pArrayVar, out VARIANT pVar);
/*[id(0x00000005)]*/ int Composite(ref SAFEARRAY pArrayVar, out VARIANT pVar);
/*[id(0x00000006)]*/ int Convert(ref SAFEARRAY pArrayVar, out VARIANT pVar);
/*[id(0x00000007)]*/ int Identify(ref SAFEARRAY pArrayVar, out VARIANT pVar);
/*[id(0x00000008)]*/ int Mogrify(ref SAFEARRAY pArrayVar, out VARIANT pVar);
/*[id(0x00000009)]*/ int Montage(ref SAFEARRAY pArrayVar, out VARIANT pVar);
/*[id(0x0000000A)]*/ int Stream(ref SAFEARRAY pArrayVar, out VARIANT pVar);
/*[id(0x0000000B)]*/ int TestHarness(ref SAFEARRAY pArrayVar, out VARIANT pVar);
/*[id(0xFFFFFFFC)]*/ int get__NewEnum(out IUnknown pVal);
/*[id(0x00000000)]*/ int get_Item(VARIANT varIndex, out VARIANT pVal);
/*[id(0x0000000E)]*/ int get_Messages(out VARIANT pVal);
}

// CoClasses

// MagickImage Class
abstract class MagickImage {
/*[uuid("5630be5a-3f5f-4bca-a511-ad6a6386cac1")]*/
static GUID CLSID = { 0x5630be5a, 0x3f5f, 0x4bca, 0xa5, 0x11, 0xad, 0x6a, 0x63, 0x86, 0xca, 0xc1 };
mixin CoInterfaces!(IMagickImage);
}


the cpp version early binding example:
Quote:
https://www.imagemagick.org/subversion/contrib/trunk/win32/ATL7/ImageMagickObject/
https://www.imagemagick.org/subversion/contrib/trunk/win32/ATL7/ImageMagickObject/MagickCMD.cpp




a great new is juno 0.35+ includ juno.media, maybe use juno.media to handle image rather than use imagemagick, would you please show me a simple example to draw text to a jpg or gif image by juno.media ?


Last edited by yidabu on Thu Aug 02, 2007 5:48 pm; edited 1 time in total
Back to top
View user's profile Send private message
John



Joined: 17 Jan 2006
Posts: 75

PostPosted: Thu Aug 02, 2007 4:56 am    Post subject: Re: ImageMagick and juno Reply with quote

Quote:
What problem with it ? and how to fix it ?


I think the function signature for Convert is wrong. Try this:

Code:
int Convert(ref SAFEARRAY* pArrayVar, out VARIANT pVar);


And then call it like this:

Code:
im.Convert(pa, v);

// Don't forget to free the memory.
SafeArrayDestroy(pa);



Quote:
would you please show me a simple example to draw text to a jpg or gif image by juno.media?


It wraps GDI+ and is very similar to .NET's System.Drawing namespace, and to a lesser extent the C++ GDI+ classes. You should be able to use any of the C# examples on the web and make them work with juno.media. Here's a quick one:

Code:

// Create a bitmap 200x100 pixels.
scope image = new Bitmap(200, 100);

// Get the bitmap's drawing surface
scope graphics = Graphics.fromImage(image);

// Create a font
scope font = new Font("Arial", 20, FontStyle.Bold);

// Create a brush
scope brush = new SolidBrush(Color.crimson);

// Draw the text on the surface
graphics.clear(Color.aliceBlue);
graphics.drawString("Hello, World", font, brush, 10, 10);

// Save the image to a file
image.save("test.jpg");
Back to top
View user's profile Send private message
John



Joined: 17 Jan 2006
Posts: 75

PostPosted: Thu Aug 02, 2007 6:54 am    Post subject: Reply with quote

By the way, this has uncovered a bug in Tlbimpd. It seems that SAFEARRAYs are always pointers. When Tlbimpd generates type names, it should be adding "*" to SAFEARRAYs.

I've fixed this for the next release - but in the meantime you should change all occurrences of "SAFEARRAY" to "SAFEARRAY*" in Tlbimpd-generated modules. (Don't remove "ref" and "out" attributes though.)
Back to top
View user's profile Send private message
yidabu



Joined: 21 Apr 2007
Posts: 87

PostPosted: Thu Aug 02, 2007 3:41 pm    Post subject: Reply with quote

D Array works with same type value,
how to set different type value? such as
"-pointsize",50

Same type value works fine:
Code:
   IMagickImage im = MagickImage.coCreate!(IMagickImage)(ExecutionContext.InProcessServer);
   assert(im, "failed im");
   scope(exit) tryRelease(im);
      
   string[] args = [r"D:\My Documents\My Pictures\old.JPG", r"D:\My Documents\My Pictures\new.gif",
      "-encoding", "Unicode", "-font", "arialuni.ttf", "-fill", "blue",
   "-gravity", "southeast", "-draw", "bbs.yidabu.com "]

   // how to set "-pointsize",50
   SAFEARRAY* pa = toSafeArray(args);

   VARIANT v;
   auto hr =im.Convert(pa, v);
   assert(SUCCEEDED(hr));
   SafeArrayDestroy(pa);   


Tupe of different type value:

Code:
template Tuple(E...)
{
   alias E Tuple;
}
   alias Tuple!(r"D:\My Documents\My Pictures\old.JPG", r"D:\My Documents\My Pictures\new.gif",
      "-encoding", "Unicode", "-font", "arialuni.ttf", "-fill", "blue",
   "-gravity", "southeast", "-draw", "bbs.yidabu.com ", "-pointsize",50) args;

   // how to set "-pointsize",50
   SAFEARRAY* pa = toSafeArray( args);


cause compile time error:
Quote:
toSafeArray(T) does not match any template declaration ...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Juno All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group