Aspimage components implementation process

zhaozj2021-02-16  47

Aspimage components implementation process

Before reading this article, it is best to have access to the following GDI Use the ATL to generate the component STLASP Using Component Aspimage is a very good component on the ServerObjects site, which allows us to use ASP to implement a lot of processing features for graphics, his Powerful, if you need to know more detailed information you can access its official website, you don't talk about how to use this component here, what we have to do this, of course, the following example uses GDI Not the only way to implement component graphics processing, you can try other methods yourself. The following is the implementation process 1. First use the Visual C wizard to establish an ATL project 2, next to add an ATL Active Server Page component interface class three, Generate classes named asppiccom, and select 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 Usage. FontStyle = 8imgFormat Property Graphics Format String Type Image / Gif Image / JPEG Image / BMP ... Usage. IMGFORMAT = "Image / GIF" setFontColor method settings Font Color How to use. The numbers ofsetfontcolor 255, 3,242,4 represents Alpha, Red, Green, BlueSetBackColor Method, set font background color usage .SetBackColor 255, 3,242,4 The numbers on the above representations Alpha, Red, Green, BlueshowPIC Method Send pictures 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; Moreover, you need to connect to GDIPLUS.LIB library #pragma Comment (Lib, "Gdiplus.lib") 2, declare ulong_ptr gdiplustoken; is a global or class of internal member variables. 3, added in the implementation class FinalConstruct functions: GdiplusStartupInput gdiplusStartupInput; // initialize GDI GdiplusStartup (& gdiplusToken, & gdiplusStartupInput, NULL); 4, added in FinalRelease function: GdiplusShutdown (gdiplusToken); so you can use the graphics processing GDI provided Function. 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 / sixth is the implementation of these attributes and methods listed in the fourth, specific code, please download my instance code below the SHOWPIC method, other code, please check 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); boundRect.Width = boundRect.Width * 2;; Graphics * g = Graphics :: (& bm) FromImage SolidBrush solidbrush (m_cBackground); g-> FillRectangle (& solidbrush, boundRect) ; SolidBrush SolidFont (m_cFontColor); PointF fPoint (0,0); g-> DrawString (OLE2CW (m_bstrText), m_bstrText.Length (), & font, fPoint, & SolidFont); int result; CLSID pngClsid; result = GetCodecClsid (OLE2W ( m_btrimgformat); HRESULT HR; HGLOBAL HGLOBAL = GLOBALLOC (GMEM_MOVEABLE, 0); ccomptr PSTM; IF (Failed (Hr = CreateStreamonhglobal (Hgloba l, TRUE, & pStm))) return hr; bm.Save (pStm, & pngClsid, NULL); ULONG cElements = (ULONG) GlobalSize (hGlobal); LPBYTE lpData = (LPBYTE) GlobalLock (hGlobal); SAFEARRAY * pArray = SafeArrayCreateVector ( VT_UI1, 0, cElements); for (UINT iElement = 0; iElement cople_contenttype (m_btrimgformat); m_piresponse-> binarywrite (vbytes); m_piresponse-> end ();

7. Now the implementation of the component is highly gotten. 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%> < / html> Note: In the User Registration Components Regsvr32 asppic.dll Open this ASP page, you will see the following picture Now achieve the specific ideas of Aspimage, now you need more effects, you can enrich your own This component looks out: This type of component is very wide, such as Yahoo.com registered a graphic word to prevent computer from automatically register, because the computer should identify the text on the picture is inefficient and it is very difficult, this class Components are more use to build to the chart, such as histogram, pie chart, waveform, etc. This article is written here. If you think there is any opinion or I am wrong place, please tell me email: sillyboy@china.com THX

转载请注明原文地址:https://www.9cbs.com/read-24684.html

New Post(0)