Implementation of ASPImage components: sillyboy switched http://www.vckbase.com/document/viewdoc/?id=524 download the source code examples in this article before reading this article, it is best to contact the following items
GDI Use the ATL Generation Components STL ASP Using Components Aspimage to be a very good component on the ServerObjects site, it can make us use the ASP to implement a lot of processing features for graphics, if you need to know more detailed information, you can visit you Its official website, does not talk about how to use this component, we are here to implement such components, of course, using GDI in the following examples is not the only way to implement component graphics processing, everyone can also Try other ways. Here is the implementation process 1. First use the Visual C Wizard to establish an ATL item 2, then add an ATL Active Server Page component interface class 3, generate the name as ASPCOM, and select the ASP internal object Response 4, Add attributes and methods on the IASPCM interface, as follows
Name Category Meaning Call Method FontName Attribute Font Name String Type Usage How to Use. FontName = "Song" FontSize Attribute Font Size Integer How to Use Property Font Type Shaped Regular = 0, Bold = 1, Italic = 2, BoldiC = 3, underline = 4, strikeout = 8 How to use .FontStyle = 8imgFormat property graphic format string type image / gifimage / jpegimage / bmp ... Use method. IMGFORMAT = "image / gif" setFontColor method Set font color How to use .SetFontColor 255, 3, 242, 4 represents Alpha, Red, Green, BlueSetBackColor method, respectively,. Method for font background color usage .SetBackColor 255, 3, 242, 4 The numbers on the above representations Alpha, Red, Green, BlueshowPIC Method Picture Send to the client usage. SHOWPIC 5. To use GDI in the ASP component, you need to add some code 1, you need to add the following two lines in the stdafx.h file: #include
Using namespace gdiplus; and need to connect to GDIPLUS.LIB library #pragma Comment (Lib, "GDIPLUS.LIB") 2, declare ulong_ptr gdiplustoken; for a global or class internal member variable. 3. Add: GDIPLUSTARTUPINPUT GDIPLUSSTARTUPInput;
// Initialize GDI
GDIPLUSSTARTUP (& GDIPLUSTOKEN, & GDIPLUSSTARTUPINPUT, NULL); 4, add: GDIPLUSSHUTDOWN (GDIPLUSTOKEN) in the FinalRelease function; so you can use the graphics processing function provided by GDI . Note: Without GDI , you can find the following URLs http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/gdi /gdi .asp http: // www .codeProject.com / VCPP / GDIPLUS / Six will be connected to these attributes and methods listed in the fourth, and the specific code, please download my instance code below the SHOWPIC method, other code, please view the source code Bitmap Bitmap (1, 1, pixelformat48bpprgb);
Graphics Graphics (& Bitmap); Uses_Conversion;
Font Font (OLE2CW (M_BstrfontName), (Float) m_ffontsize, m_nfontstyle, unitpoint, null;
Pointf Origin (0, 0);
StringFormat Format;
Format.SetAlignment (StringAlignmentCenter);
Rectf BoundRect;
Graphics.measureString (OLE2CW (M_BSTRTEXT), M_BSTRTEXT.LENGTH (), & FONT, ORIGIN, & FORMAT, & BoundRect)
INT nwidth = (int) boundrect.width;
INT NHEIGHT = (int) BoundRect.height;
Bitmap BM (NWIDTH, NHEIGHT, PIXELFORMAT48BPPRGB);
Graphics * g = graphics :: fromImage (& BM);
BoundRect.width = BoundRect.width * 2;
Solidbrush Solidbrush (M_CBACKGROUND);
g-> FillRectangle (& Solidbrush, BoundRect);
Solidbrush SolidFont (M_CFONTCOLOR);
Pointf fpoint (0);
G-> DrawString (OLE2CW (M_BSTRText), M_BSTRText.length (), & font, fpoint, & solidfont;
Int result;
CLSID PNGCLSID;
Result = getcodecclsid (OLE2W (m_btrimgformat), & pngclsid;
HRESULT HR;
Hglobal Hglobal = GlobalLoc (GMEM_MOVEABLE, 0);
CComptr
IF (FAILED (Hr = CreateStreamonhglobal (Hglobal, True, & PSTM)) Return HR;
Bm.save (PSTM, & PNGClsid, NULL);
Ulong Celements = (Ulong) GlobalSize (Hglobal);
LPBYTE LPDATA = (LPBYTE) Globalock (Hglobal);
SafeArray * parray = SafeArrayCreateVector (VT_UI1, 0, CELEMENTS);
For (uint ilement = 0; Ilement { Long idx = ilement; SafearrayPutelement (PARRAY, & IDX, ((lpbyte) lpdata) ilement); } GlobalUnlock (Hglobal); CComvariant Vbytes; vbytes.vt = vt_Array | VT_UI1; vbytes.parray = parray; m_piresponse-> clear (); M_Piresponse-> Put_ContentType (m_btrimgformat); m_piresponse-> binarywrite (vbytes); m_piresponse-> end (); Seven, now the implementation of the component is very big, we write a paragraph ASP to test the following components <% @ language = "VBScript" CodePage = "936"%>
<%
Set Picture = Server.createObject ("asppic.asppiccom")
Picture.text = "Can you see me? I am from www.goodassister.com!"
Picture.FontName = "black body"
Picture.fontsize = 40
Picture.Imgformat = "image / jpeg"
Picture.FontStyle = 1
Picture.SetFontColor 255, 3, 242, 4 '' represents Alpha, Red, Green, Blue
Picture.setbackColor 10,243,42,54 'represents Alpha, Red, Green, Blue
Picture.showpic
Set Picture = Nothing
%>
body>
html> Note: In the use of the first registration component regsvr32 asppic.dll Open this ASP web page, you will see the following picture to achieve the specific ideas of Aspimage, now you need more effect, you can Enrich this component: This type of component is very wide, such as Yahoo.com registered a graphic word to prevent computer from automatically register, because the computer is to identify the text on the picture is inefficient and it is very difficult, this More components are more use to generate generation, such as histograms, pie charts, waveforms, etc. This article is here, if you think there is any opinion or I am telling the wrong place, please tell me email: sillyboy@china.comthx