Introduction Samples Interfaces Buy Support Site Home

SDraw --- Sample Codes --- JavaScript


// Create a 320*320 image
IMG.CreateImage(320, 320);
IMG.FillRect(0, 0, 320, 320, "0, 0, 128");
IMG.FillRect(20, 20, 300, 300, "255, 255, 255");

// Draw an ellipse
var pen=IMG.CreatePen();
pen.SetWidth(1);
pen.SetColor("254, 254, 254");
pen.Ellipse(160, 130, 125, 100);

// Cut the ellipse into 4 by drawing lines
var x=125*Math.cos(Math.PI/4);
var y=125*Math.sin(Math.PI/4);
pen.SetColor("254, 254, 254");
pen.SetWidth(20);
pen.MoveTo(160+x, 130-y);
pen.LineTo(160-x, 130+y);
pen.MoveTo(160-x, 130-y);
pen.LineTo(160+x, 130+y);

// Fill each of the 4 pieces with color
IMG.FloodFill(160, 50, "255, 128, 0");
IMG.FloodFill(160, 160, "255, 128, 0");
IMG.FloodFill(50,  130, "0, 128, 255");
IMG.FloodFill(200, 130, "0, 128, 255");

// Cut again, now we get 8 pieces
IMG.FillRect(20, 120, 300, 140, "255, 255, 255");
IMG.FillRect(150, 20, 170, 300, "255, 255, 255");

// Draw text
var text=IMG.CreateText();
text.SetAntialias(true);
text.SetFont("Arial Black", -64, 900);
text.SetTextColor("128,128,128");
text.Draw("SDRAW", 160, 300, 6);


// Put the image into a clipboard
var cp320=IMG.CreateClipboard();

// Put the image into a second clipboard, and resample it to 32*32
var cp32=IMG.CreateClipboard();
cp32.Resample(32, 32);

// Put the image into a third clipboard, and resample it to 16*16
var cp16=IMG.CreateClipboard();
cp16.Resample(16, 16);

// Create an image large enough for the 3 icons in clipboars
IMG.CreateImage(400, 320);
cp320.Draw(160, 160, 9);
cp32.Draw(320+40, 80, 9); 
cp16.Draw(320+40,  240, 9);

// save the image. If not licensed, this will not work
IMG.SaveImage("icon.gif");