T1CFreeImage is a simple ATL
component that creates PNG images on the fly.
T1CFreeImage is a simple ATL component that creates
PNG images on the fly. It draws lines and texts with a selected
color and saves the rendered image to a file. The component can be
used with ASP, Word, Excel and any other applications that support
ActiveX. It's supplied with full source code that you can easily
extend with your own functions and use new versions of libraries as
they become available.
Platform: Windows 95/98/NT/2000.
The more advanced and comprehensive ActiveX Image component can be
found at http://www.tonec.com/download4.html.
It fully supports Jpeg images (it doesn't support GIF since Unisys
holds patent on LZW compression that is used in GIF format), direct
stream data output, image reading/writing to a file and databases.
It also works with different image sets, has many additional
functions like text output with a selected slope, graphic
primitives drawing, filled polygon, etc.
If you want to build T1CFreeImage ActiveX component yourself, you
will need to compile libraries (gd, libpng, zlib) first and then
compile T1CfreeImage source files. To compile the libraries you
need to create three subdirectories (gd, libpng, zlib) in your
project home directory tree.
|
To build the component in MS VC 6.0 ++, you need to
:
- Create T1CfreeImage project in ATL??? working
directory (T1CFreeImage by default).
- Add ATL simple object and name it Images. (Menu Insert->New ATL object)
- In Project Settings, click on C/C++ tab and select
Preprocessor Category in listbox, then add Additional include directories
"../gd", "../libpng", "../zlib"
- Click on the "Link" tab, select "Input" category in the listbox
and add Object/library
modules: "libpng.lib" "zlib.lib" "gd.lib" to the end of the list.
Also add "Additional library path": "../libpng/Release",
"../zlib/Release", "../gd/Release" or other path
depending on where these libraries are located.
- Add #include "gd.h" line in Images.h file
right after #include "resource.h" line
- Add #include "gdfonts.h" in image.cpp right
after #include "Images.h" line
- Add img member variable, set type to
gdImagePtr. Access - public
- Add color variable. Add member variables with
variables Type int. Access - public
- Add the following methods with the following
code:
- Method Name: CreateImage
Parameters: [in] int w, [in] int h
Add the code:
int white;
img = gdImageCreate(w, h);
white = gdImageColorAllocate(img, 255, 255, 255);
- Method Name: SetColor
Parameters: [in] int R, [in] int G, [in] int B
Add the code:
color = gdImageColorAllocate(img,
R, G, B);
if (color == (-1)) {
color = gdImageColorAllocate(img, R, G, B);
color = gdImageColorClosest(img, R, G, B);
}
- Method Name: DrawLine
Parameters: [in] int x1, [in] int y1, [in] int x2, [in] int
y2
Add the code:
gdImageLine(img x1, y1, x2, y2,
color);
- Method Name: DrawText
Parameters: [in] int x, [in] int y, [in] BSTR str
Add the code:
CHAR *lpString;
int iMessageSize;
iMessageSize=wcslen(str)+1;
lpString = new CHAR[iMessageSize];
// Change the Message From Unicode to MBCS
if
(WideCharToMultiByte(CP_ACP,0,str,-1,lpString,iMessageSize,NULL,NULL)==FALSE)
{
return(S_FALSE);
}
gdImageString(img, gdFontSmall, x, y, (unsigned char *)lpString,
color);
delete lpString;
- Method Name: SaveToFile
Parameters: [in] BSTR strFile
Add the code:
FILE *out;
CHAR *lpString;
int iMessageSize;
iMessageSize=wcslen(strFile)+1;
lpString = new CHAR[iMessageSize];
// Change the Message From Unicode to MBCS
if
(WideCharToMultiByte(CP_ACP,0,strFile,-1,lpString,iMessageSize,NULL,NULL)==FALSE)
{
return(S_FALSE);
}
out = fopen(lpString, "wb");
/* Write PNG */
gdImagePng(img, out);
fclose(out);
delete lpString;
- Compile and build the project
- Register the component if needed. You will need it
if you use DLL from our distribution file or if you use it on
another computer.
|
Here is the sample (t1c.vbs) that shows the usage of
free ActiveX component on your ASP page. You can also use the
component from VBS file, VBA for Access, Words and any other
applications that support ActiveX (ATL) components.
Dim im
Set im = CreateObject("T1CFreeImage.Images.1")
im.CreateImage 100,100
im.SetColor 255,0,0
im.DrawLine 10,10,30,30
im.SetColor 0,0,255
im.DrawText 10,40,"T1CFreeImage"
im.SaveToFile "C:\test.png"
Set im = Nothing
Figure 1. Test.png
Download T1CFreeImage.zip
with full source code and binary DLL (version 0.95).
The more comprehensive and advanced version of
component will become available in the middle of April, 2001. It
will support Jpeg images and include text output with a slope,
direct read/write to a stream, databases, ASP variable and file,
more graphics primitives and error handling. The last release can
be found at http://www.tonec.com/download4.html
Note that Tonec Inc. also provides custom programming and
cost-effective offshore software
development services. Check out our Free Products page.
If you have any questions, write to info@tonec.com
|