Welcome Guest! You need to login or register to make posts.



Go to last post Go to first unread
jeremy llewiff  
#1 Posted : Monday, March 27, 2006 6:22:42 PM(UTC)
jeremy llewiff

Rank: Member

Groups: Member
Joined: 3/25/2006(UTC)
Posts: 3

I'm using GraphicsMill for a webapp where people can save coordinates and transform an image based on thos coordinates. It uses Transforms.ProjectivePoints and that part works great. Kudos for such a powerful transform feature.

But I have trouble drawing a simple triangle on the image.

According to the reference, DrawPolygon takes an Array of points. But when I supply one, I get the following ASP error:

GraphicsMill.Bitmap.2.0 error '80070057'

Method DrawPolygon failed. You try to use non-array variable.

Here's my code:

var foo = new Array(20,20, 100,20, 100,150);
imageObject.Graphics.DrawPolygon(foo, true, false, 0);

I'm pretty sure that's an Array. ;)

Edited by user Thursday, December 20, 2007 4:56:34 PM(UTC)  | Reason: Not specified

jeremy llewiff  
#2 Posted : Wednesday, March 29, 2006 7:01:47 PM(UTC)
jeremy llewiff

Rank: Member

Groups: Member
Joined: 3/25/2006(UTC)
Posts: 3

Here's an interesting plot twist: it works if I translate the JScript to VB.

So then I set up two .asp's using code from the Online Help. I translated one to JScript. The VBscript one works, the JScript one gives the error.

I'm stumped. How can this module be VB dependent?

#3 Posted : Sunday, April 2, 2006 3:18:11 PM(UTC)

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Well... When we implemented this functionality, we did not test it with JScript. We get it working only for VBScript. The only kind of arrays supported in VBScript is SAFEARRAY of VARIANTs (moreover, it must be VARIANT as well). Perhaps JScript works with arrays differently. I have submitted it to developers to examine this.

However if you do not want to use VBScript, there is a workaround. To tell the truth it is looking pretty ugly, but it works.

The idea is to use Graphics Mill to produce SAFEARRAY of numbers. For example, we can use Palette object for this.

  1. Create Palette object and initialize it with some predefined palette.

  2. Create fake bitmap 1x1 and associate it with the palette.

  3. To reduce number of palette entries to the necessary number (e.g. for triangle we need only 6 entries instead of 256), convert this bitmap and pass number of required "colors".

  4. Modify palette entries by writing coordinates (instead of colors).

  5. Set ColorTreatment of the bitmap to ColorTreatment0Rgb to avoid adding alpha channel during export from palette to array.

  6. Export palette to array using ExportToArray method.

After that you can pass this array to DrawPolygon method.

Here is a code sample. If you have any problems with it, please let me know.


<!-- METADATA TYPE="typelib" UUID="{3CE48541-DE7A-4909-9314-9D0ED0D1CA5A}"-->
<%@ Language=JScript %>
var objBitmap
objBitmap = Server.CreateObject("GraphicsMill.Bitmap");

objBitmap.CreateNew (185, 145, Format24bppRgb);
objBitmap.Graphics.Engine = DrawingEngineGdiplus;
// How many array elements you need to have. In case of triangle it is 6.
// NOTE: You cannot specify more than 256 elements!
var coordCount = 6; 

// To create an array, compatible with Graphics Mill, we will return it
// from Palette object. It will also require to create temporary bitmap object.
// Do not change hardcoded values, otherwise it may stop working :-)
var objPalette = Server.CreateObject("GraphicsMill.Palette");
objPalette.GeneratePredefined(PaletteTypeWindows, true);

var objTmpBmp = Server.CreateObject("GraphicsMill.Bitmap");
objTmpBmp.CreateNew(1,1,Format8bppIndexed, 0, objPalette);

objTmpBmp.Data.ConvertTo8bppIndexed (0, 1, 0, 2, coordCount, 1, objPalette);
objPalette = objTmpBmp.Data.Palette;
objTmpBmp.ColorTreatment = ColorTreatment0Rgb;

// Initialize "palette" entries with necessary coordinates.
objTmpBmp.Data.Palette(0) = 20;
objTmpBmp.Data.Palette(1) = 30;
objTmpBmp.Data.Palette(2) = 50;
objTmpBmp.Data.Palette(3) = 2;
objTmpBmp.Data.Palette(4) = 180;
objTmpBmp.Data.Palette(5) = 30;

// Export palette entries into array (it will be SAFEARRAY of VARIANTs)
var ar;
ar = objTmpBmp.Data.Palette.ExportToArray();

objBitmap.Graphics.DrawPolygon (ar);

objBitmap.SaveToFile (Server.MapPath("/GraphicsMill/ResultImages/DrawShapes.png"));

Edited by user Thursday, December 20, 2007 4:56:48 PM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.