MainExamplesDocumentationRegistration  


 Info
What is ShotGraph
Why use ShotGraph
Download
How to register
FAQ


 Making images
Common principles
Palettes
OLE support
ShotGraph on 64-bit Windows
Creating animations
Trick: anti-aliased fonts
 

The common principles of creating images with ShotGraph

ShotGraph is an COM automation server. Therefore, you need to have an COM automation controller application to use it. There are a number of applications which can be used as Automation controllers. For example, you can use the following:
Visual Basic
VBScript
Visual Basic for applications (VBA), Word, Excel, etc.
Active Server Pages (ASP) engine built in Internet Information Server
Perl for Windows
others

ShotGraph basics

In the most of cases an instance of ShotGraph object created by your script (application) should have the imagespace. The imagespace is a special memory located data structure maintained by ShotGraph object, where ShotGraph holds and handles image data. Therefore, if you want to perform some image operations using ShotGraph or create new image in any supported data format then you should create imagespace.

The object can have up to two imagespaces. One of the imagespaces is a primary imagespace, and the other one is a secondary imagespace. The primary imagespace is created by CreateImage method. Practically, this method is called in almost every script.

The secondary imagespace (optional, named 'local clipboard' too) is created by InitClipboard. The secondary imagespace is used as a buffer to keep the whole image or its part for later transformations, for example, for such operations as copying, stretching or applying transparency mask.

The application can use both primary and secondary imagespace for drawing new image data and loading existing images from files, however, the result image (using GifImage, JpegImage and similar methods) can be taken only from the primary imagespace.

Step by step

This is a typical scenario for creating new image containing custom drawings: texts, standard shapes etc.
  1. First, create an object of type "shotgraph.image".
  2. Call CreateImage specifying necessary dimensions of primary imagespace in pixes. This will be size of result image.
  3. If you have some ready image file for background then load data from that image into primary imagespace by calling ReadImage.
  4. Call SetColor method one or several times to define and get easy access to the colors will be used to draw the image.
  5. If necessary, clear the whole or part of imagespace by calling FillRect.
  6. Call neccessary functions in accordance with logic of your application to perform drawings.
  7. Call GifImage (JpegImage etc.) function. Your image is ready!
You can read more about these an other function of ShotGraph on the Methods & properties page.

The following simple example demonstrates how to create the image on the right-hand side with ShotGraph
The size of the image is 201x201.

Code on VBScript

'Creating the object
set obj=CreateObject("shotgraph.image")

size=201
'Calling the CreateImage method
obj.CreateImage size,size,4

'Set 4 colors for drawing
obj.SetColor 0,255,255,255
obj.SetColor 1,0,0,0
obj.SetColor 2,255,108,0
obj.SetColor 3,0,0,204

'Crearing the painting area with color 0
obj.SetBgColor 0
obj.FillRect 0,0,size-1,size-1

'Color 0 will be used for drawing
obj.SetDrawColor 1
'Drawing the line
obj.Line size-1,0,0,size-1
'Color 2 will be used for filling
obj.SetBgColor 2
'Draw the big circle
obj.Ellipse 5,5,size-6,size-6
'Color 2 will be used for filling
obj.SetBgColor 3
'Draw the small circle
obj.Ellipse 5,(size-5)/4,size/2,(size-5)*3/4

'Create the image file named test.gif
obj.GifImage 0,1,"test.gif"
The same example are in ASP and in Perl:
ASP

Response.ContentType="image/gif"
set obj=Server.CreateObject("shotgraph.image")

size=201
obj.CreateImage size,size,4
obj.SetColor 0,255,255,255
obj.SetColor 1,0,0,0
obj.SetColor 2,255,108,0
obj.SetColor 3,0,0,204
obj.SetBgColor 0
obj.FillRect 0,0,size-1,size-1

obj.SetDrawColor 1
obj.Line size-1,0,0,size-1
obj.SetBgColor 2
obj.Ellipse 5,5,size-6,size-6
obj.SetBgColor 3
obj.Ellipse 5,(size-5)/4,size/2,(size-5)*3/4

img=obj.GifImage(0,1,"")
Response.BinaryWrite img
Perl

$obj=CreateObject("shotgraph.image")

$size=201
$obj->CreateImage($size,$size,4)
$obj->SetColor(0,255,255,255)
$obj->SetColor(1,0,0,0)
$obj->SetColor(2,255,108,0)
$obj->SetColor(3,0,0,204)
$obj->SetBgColor(0)
$obj->FillRect(0,0,$size-1,$size-1)

$obj->SetDrawColor(1)
$obj->Line($size-1,0,0,$size-1)
$obj->SetBgColor(2)
$obj->Ellipse(5,5,$size-6,$size-6)
$obj->SetBgColor(3)
$obj->Ellipse(5,($size-5)/4,$size/2,($size-5)*3/4)

$obj->GifImage(0,1,"test.gif")

© 1998-2001 Mikhail Tchikalov
Email to contact: mtchikalov@usa.com