Develop ASP image processing components with VC ++

xiaoxiao2021-03-06  50

Use VC Development ASP image processing component author: Fu Arts (Fei) Published: 2004-04 Author: Fu Arts Northwest Normal 2001 computer adult undergraduate E-Mail vc@hahame.net Contact: 13359319378 0931-8553848 Website http : //www.orcode.net code download: http://www.nwnu.net/src/xtaspimage_to_vckbase.rar A VC DC Environment and GUI Related objects There are various graphical user interface in Windows ( GRAPHICS User Interface Object When we need to use these objects when drawing. Various objects have a variety of properties, let me introduce several GUI objects and owned properties. (1) GUI's various objects have various graphics user interface objects in Windows, when we need to take advantage of these objects when making a drawing. Various objects have a variety of properties, let me introduce several GUI objects and owned properties. Font Objects CFONT Font Objects CFont When you output text, you will use different styles and size fonts. The selectable style includes: whether it is a slope, whether it is a bold, the font name, whether it is underscore, etc. The brush CBRUSH object brush CBRush object determines the color or template employed when the area is filled. For a fixed color brush, its attribute is color, whether the type of grid and grid is used, vertical, cross-like, etc. You can also create a brush of a custom template using a bitmap of 8 * 8, and the system will use the bitmap to step by step by step by using this brush. Brush CPEN brush Cpen object is useful when drawing points and lines. Its properties include color, width, line style, such as dashed lines, solid lines, dotlines, etc. Bitmap CBITMAP Object Bitchart CBITMAP object can contain an image and can be saved in the resource. The CPalette palette CPALETTE palette is a color map interface that allows applications to take advantage of the color drawing capabilities of the output device without affecting other applications. In addition, there are some stock GUI objects, you can use CDC :: SelectStockObject (SelectStockObjectStockObject (SelectStockObject (INT NINDEX) to select these objects, including some fixed color brush, brush, and some basic fonts. Such as: Black_brush black brush Null_brush empty brush White_Pen White Brush Device_Default_Font Default Font Use the GUI object in Windows. You must comply with certain rules. First, you need to create a legal object, different object creation methods are different. Then you need to select the GUI object to the DC while saving the original. GUI object. If an illegal object will cause an exception. It should restore the original object after use, this is especially important if you save a temporary object in DC, and may cause an exception after the temporary object is destroyed.

One must pay attention to that every object must be destroyed before recreation, the following code demonstrates this safe usage: OnDraw (CDC * PDC) {a) CPEN PEN1, PEN2; B) Pen1.createpen (PS_SOLID, 2, RGB (128, 128, 128)); // Create a brush object a c) Pen2.createpen (PS_SOLID, 2, RGB (128, 128, 0)); // Creating a brush object 2 d) CPEN * POLDPEN = (CPEN *) PDC- > Selectobject (& PEN1); // Select Object into DCE) DrawWithpen1 ... f) (CPEN *) PDC-> SelectObject (& Pen2); // Select Object into DCG) DRAWWITHPEN2 ... H) Pen1.deleteObject (); DELETEOBJECT (); //, first destroy I) Pen1.createpen before being created again (PS_SOLID, 2, RGB (0, 0, 0)); // Create Object J) (CPEN *) PDC-> SelectObject (& Pen1); // Select Object DCK) ​​DRAWWITHPEN1 ... L) PDC-> SelectObject (POLDPEN); // Recovery} The Ondraw (CDC * PDC) function is the most common graphic output refresh function in the VC, the parameter PDC is a pointer to the CDC class, we pass It draws draws. Code A line defines two brush objects PEN1, PEN2 of the CPEN class, and calls CPEN CPEN class members in row B, C creates two solid brushes, and its color RGB value is RGB (128, 128, 128), RGB (128, 128, 0) . Line D selects the newly created brush PEN1 into the current device context DC environment and saves the old brush in the Poldpen so that the graphic or text line output in the E row will populate the properties of PEN1. f, the G line is selected into the brush two and output. I, J Marketing Destroyed Pen 1 and creates RGB (0,0,0) color brush, K row output. The last row L line selects the old brush into the current DC environment and outputs it. The method of use of font objects, brush objects, and bitmap objects is the same, and the specific use will be described in the following instance. A DC object is required when drawing, the DC (Device Context Device Environment) object is an abstract mapping environment, which may be a corresponding screen or other printer or others. This environment is independent of the device, so it is only necessary to use different device environments when outputting different devices, and mapping can be completely unchanged. (2) The output text in the DC environment has a device environment class CDC in the MFC encapsulates the output of physical equipment. The CDC is the base class of the equipment environment is directly derived from COBJECT. It is a key element of the graphical device interface, which represents a physical device. Each C device environment object has a corresponding Windows device environment and is identified by a 32-bit type HDC handle. The virtuality of the CDC class makes us easy to write code for multiple devices while making it easier. For example, the onDraw function PDC-> TextOut (0, 0, "Hello"); can be applied to the display, but also to print preview and printing, just point to different object classes at the PDC parameter of the CView :: OnDRAW function. CClientDC and CWindowDC are displayed devices, which are derived from CDCs that distinguish between CClientDC is the client area of ​​the window does not include a border, title bar, and menu bar, (0) refers to the upper left corner of the customer area. CWindowDC (0,0) refers to the top left corner of the entire screen, which means we can draw any place in the monitor, including window borders, title bar, and menu bar, and more. CWindowDC is generally applied to the frame window instead of the view window.

After the CDC object is created, be sure to delete it when it is appropriate, and if you forget the delete device environment, you will cause memory loss. The following block is implemented in the DC environment output text.

. Long CImg :: OutImgFromText (LPCTSTR vFileName, LPCTSTR lpText, LPCTSTR lpBgImg, long lCSet, LPCTSTR lpFont, long lWidth, long lHeight, long lLeft, long lTop, long llfHeight, long lWeight, long l3D) {i m_nWidth = lWidth; ii . m_nheight = LHEIGHT; III. IF ((m_nwidth% 8)! = 0) 1. m_nwidth = (INT) (m_nwidth / 8) 1) * 8; IV. IF (m_nwidth <3 * lleft) 1. m_nwidth = 3 * LLEFT; V. IF (M_NHEIGHT <3 * LTOP) 1. M_nheight = 3 * LTOP; VI. Int nfheight = LLFHEIGHT; VII. IF (0 == nfheight) 1. Nfheight = 1; Viii. Int nRealClientWidth = (m_nwidth - 2 * llef); IX. HDC HDC; X. HDC = CreateCompatibleDC (NULL); xi. logfont lf; xii. Memset (& lf, 0, sizeof (lf)); xiii. lf.lfcharset = GB2312_CHARSET; XIV . lf.lfHeight = nFHeight; xv lstrcpy (lf.lfFaceName, lpFont);.. xvi lf.lfPitchAndFamily = 8;. xvii lf.lfWeight = lWeight;. xviii hFONT hFont = CreateFontIndirect (& lf);. 1 hFONT hOldFont = ( HFONT) SELECTOBJECT (HDC, HFont); // Select font Xix. Ccombstr bstrtext (lptext); xx. Rect rectClient = {LLEFT, LTOP, M_NWIDTH - LLEFT, M_NHEIGHT - LTOP}; xxi. :: DrawText (1. HDC, 2. Bstrtext.m_str, 3. Bstrtext.length (), 4. & RectClient, 5. DT_WordBreak | DT_LEFT | DT_CALCRECT6.); // Calculate Output Tour XXII. Int NRealHeight = RectClient.bottom lTop; xxiii if (m_nHeight

0) xxxiii. {1. // setbkcolor (HDC, RGB (200, 193, 193)); 2. SettextColor (HDC, :: GetSysColor (color_3ddkshadow); 3. SetBkmode (HDC, Opaque); xxxiv.} Xxxv. Elsexxxvi. { 1. setbkcolor (HDC, RGB (255, 255, 255)); 2. SetTextColor (HDC, RGB (0, 0)); 3. SetBkMode (HDC, Transparent); xxxvii.} Xxxviiii .:: DrawText (1. HDC, 2. BSTRTEXT.M_STR, 3. BSTRTEXT.LENGTH (), 4. & RectClient, 5. dt_wordbreak6.); // Output xxxix. If (L3D> 0) XL. {1. setTextColor (HDC, :: getsyscolor (color_3dhilight) ); 2. setbkmode (HDC, transparent); 3. RectClient.Left = RectClient.LEFT L3D; 4. RectClient.top = RectClient.top - 1; 5. RectClient.right = RectClient.Right L3D; 6. RectClient .BOTTOM = RectClient.bottom - 1; 7. :: DrawText (a) HDC, B) LPText, C) WCSLEN (LPTEXT), D) & RectClient, E) DT_WordBreak; XLi.} XLII. SelectObject (HDC, HoldFont) ;. xliii DeleteObject (hFont);. xliv DeleteObject (hBBg);. xlv SaveDCBmp (hDC, hBitmap, vFileName); xlvi // SaveDCJPG (hDC, hBitmap, vFileName);.. xlvii DeleteObject (hBitmap); xlviii ::. ReleaseDC (NULL, HDC); XLIX. Return 0; } This function function: By entering a specific length text, output an image to the specified file parameter description: vFileName: Image save file path LPText: Image Output text LPBGIMG: Image Background LCSET: Character Set LPFONT: Font Name LWIDTH: Image Output Width LHEight : Image output height LLEFT: image output left distance, with the same LTOP: image output on the right distance, the same LLFHEIGHT: text output font height, font width with height, etc., LWEight: text Weight L3D: three D effect, When the value is 0, there is no three D effect, and the value is greater than 0 is the font offset program i. To VIII. The row checks the legality of the input parameter and is correct. Row IX., X. Define and create a device context handle HDC compatible with the specified device. Row XI. To XVIII.1 line defines the LogFont logic font structure and populates. Creating fonts by CreateFontIndirect (& lf) and call SelectObject (HDC, HFont) will create fonts to select the device context, and the original author handle is saved in HoldFont. Xix. To XXIV. Rows Get the length of the input text, call the DrawText function to calculate the output rectangle in the current font environment, and save its rectangle in the RectClient to adjust the DC output rectangle size. XXVI. Using the long-width to create a bitmap segment, line XXVII. Select it to the device context, ready to work, and the drawing work officially begins.

In this function, the brush and brush use the system default setting and no longer repeat. XXXII. It is determined whether the three d offset is greater than zero, if not zero, output three D effect. Enter text under the new rectangle. If there is a three d output request, the rectangle offers L3D pixels, and outputs the text again to display the three D effect. XLII. The line is selected into the old font. XLIII. Remove the object save bitmap and restore the site. Saving bitmap feature SavedCBMP will be discussed next section. Two bitmap files (1), bitmap file structure bitmap file consisting of three parts: file header bitmap information -ty-bit image filter data 1, bitmap file header file header is primarily used to identify bitmap files. The following is the definition of bitmap file header structure: typedef struct tagbitMapfileHeader {Word bftype; dword bfSize; word bfreserved1; word bfreserved2; dword bfofbits;} BitmapFileHeader; where the bftype value should be "BM" (0x42), the flag is bit Figure file. The value of BFSIZE is the size of the bitmap file. BFRESERVED1, BFRESERVED2 is the reserved word, the value is 0. BFoffBits is the difference between bitmap file size and DIB (independent bitmap device-indepentent bitmap) bitmap data. Such as: BITMAPFILEHEADER bmfHdr; bmfHdr.bfType = 0x4D42; // "BM" dwDIBSize = sizeof (BITMAPFILEHEADER) sizeof (BITMAPINFOHEADER) dwPaletteSize dwBmBitsSize; bmfHdr.bfSize = dwDIBSize; bmfHdr.bfReserved1 = 0; bmfHdr.bfReserved2 = 0; BMFHDR.BFOFFBITS = (DWORD) SIZEOF (BitmapFileHeader) DWPALETESIZE; 2, the value recorded in the bitmap information bitmap information is used to assign memory, set the palette information, read pixel values. Wait. The following is the definition of the bitmap information structure: TypedEf struct tagbitmapinfo {bitmapinfoheader bmiheader; RGBQUAD BMICOLORS [1];} BitmapInfo; visible bitmap information is also composed of two parts: bitmap information head color table 2.1 bitmap information head diagram The information head contains the number of bytes used and the format describing the color, and includes the width, height, the bit plane of the target device, the compression format of the image.

The following are definitions bitmap information header structure: typedef struct tagBITMAPINFOHEADER {DWORD biSize; LONG biWidth; LONG biHeight; WORD biPlanes; WORD biBitCount DWORD biCompression; DWORD biSizeImage; LONG biXPelsPerMeter; LONG biYPelsPerMeter; DWORD biClrUsed; DWORD biClrImportant;} BITMAPINFOHEADER; biSize Structure BitmapInfoHeader's byte, namely, sizeof (BitmapInfoHeader) Biwidth in pixel-based image width Biheight with image length BiPlanes target device bit number BIPTCOTCOTCOTCOTCOTCOUNT number of bits of each pixel for each pixel, There is a meaning: 0, in the JPEG format 1, monochrome map, palette contain two colors, which is black and white picture 4,16 color map 8, 256 color map, usually ash Figure 16,64k, generally no palette, each byte in the image data represents a pixel, 5 or 6 bits represents a RGB component 24, 16m true color map, generally no palette, image data Each of the three bytes represents a pixel, each byte represents a RGB component 32, 4G true color, generally no palette, each 4 bytes represent a pixel, relatively 24 real color maps, joined A transparent, ie the compression format of the RGBA mode BiCompression image (this value is almost 0) BisizeImage is in the size of the image data in bytes (in the Bi_RGB compression method) Bixpelspermeter horizontal direction of pixels per meter The number of colors actually used in the pixels of the Biypelspermeter vertically, this value is usually the number of colors necessary when the 0biClrimportant real bitmap is usually 0, indicating that all colors are required. 2.2 Color Table Color Table is typically provided for an image of 16 bits or less, an image of 16-bit and 16-bit or more, since the RGB (A) color of the corresponding pixel is described in the position of the corresponding pixel, and is therefore Palette. For images below 16 bits, since only a palette index value recorded in its bit image, it is necessary to obtain the corresponding RGB (a) color based on this index to the palette. The role of color table is to create a palette. The color table is composed of color menu, the color entries are defined as follows: typedef struct tagrgbquad {// rgbq byte rgbblue; byte rgbgreen; byte rgbred; Byte rgbreserved;} RGBQUAD; RGBBLUE Blue intensity RGBGREEN Green intensity RGBRED Red intensity RGBRESERVED reserved word, where the problem is concerned, the color order in the RGBQUAD structure is BGR, not the usual RGB. 3, bitmap data finally, after bitmap file header, bitmap information head, bitmap color table, is the main part of bitmap: bitmap data.

According to different bitmaps, the number of bytes occupied by bitmap data is also different. For example, for 8-bit bitmaps, each byte represents a pixel, for 16-bit bitmap, each two bytes represent one Pixel, for a 24-bit bitmap, each byte represents a pixel, for a 32-bit bitmap, and each four bytes represent one pixel. (2) After the storage area DC is in place diagram file, it is simple to operate in the structure of the bitmap file. By creating a specific brush, brush, bitmap objects, after drawing in a DC environment, you should store the images saved in the DC in the bitgraph file to use and output to other media. The following code implementation will set the drawing context graphic saved as bitmap file.

Bool CIMG :: SavedcBMP (HDC HDC, HBitmap Hbitmap, LPCTSTR LPFILENAME) {// Current Resolution Perpartment per pixel INT IBITS; // Bit Map The number of items per pixel is Word WbitCount; / / Define the palette size, bitmap pixel byte size, bitmap file size, write file byte DWord dwpalettesize = 0, dwbMbitssize = 0, dwdibsize = 0, dwwritten = 0; // bit map Properties Bitmap Bitmap; // bitmap file header structure BitmapfileHeader BMFHDR; // bitmap information head structure BitMapInfoHeader Bi; // points the bitmap information head structure lpbitmapinfoheader lpbi; // Define file, allocate memory handle, palette handle fh, HDIB , HPAL, HOLDPAL = NULL; // Computing bitmap file per pixel number IBITS = getDeviceCaps (HDC, Bitspixel) * getDeviceCaps (HDC, Plaso); if (ibits <= 1) wbitcount = 1; Else IF (iBITS <= 4) Wbitcount = 4; Else IF (iBITS <= 8) wbitcount = 8; Else Wbit = 24; // wbitcount = 4; GetObject (Hbitmap, Sizeof (Bitmap), (LPSTR) & Bitmap); BI. biSize = sizeof (BITMAPINFOHEADER); bi.biWidth = Bitmap.bmWidth; bi.biHeight = Bitmap.bmHeight; bi.biPlanes = 1; bi.biBitCount = wBitCount; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biypelspermeter = 0; bi.bi.birrimportant = 0; bi.bi.bi.biRused = 0; dwbmbitsSize = ((bitmap.bmwidth * wbitcount 31) / 32) * 4 * Bitmap.bmHeight; // bitmap memory content distribution hDib = GlobalAlloc (GHND, dwBmBitsSize dwPaletteSize sizeof (BITMAPINFOHEADER)); lpbi = (LPBITMAPINFOHEADER) GlobalLock (hDib); * lpbi = bi ; // Treatment palette hpal = getStockObject (default_palette); if (hpal) {holdingpal = :: selectpalette (HPALETTE) HPAL, FALSE);} // Get new pixel values ​​getDibits under this palette HDC, HBitmap, 0, (uint) Bitmap.Bmheight, (LPSTR) LPBI Sizeof (BitmapInfoHead) dwpalettesize, (BitmapInfo *) LPBI, DIB_RGB_COLORS); // Recovery palette if (Holdpal) {:: SelectPalette (HDC , (HPALETTE) HOLDPAL, TRUE); RealizePalette (HDC);

} // create a bitmap file fh = CreateFile (lpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (fh == INVALID_HANDLE_VALUE) return FALSE; // the bitmap file header bmfHdr.bfType = 0x4D42 ; // "BM" dwDIBSize = sizeof (BITMAPFILEHEADER) sizeof (BITMAPINFOHEADER) dwPaletteSize dwBmBitsSize; bmfHdr.bfSize = dwDIBSize; bmfHdr.bfReserved1 = 0; bmfHdr.bfReserved2 = 0; bmfHdr.bfOffBits = (DWORD) sizeof (BITMAPFILEHEADER ) (DWORD) SIZEOF (BitMapInfoHeader) dwpalettesize; // Write the bitmap file head Writefile (Fh, (LPSTR) & BMFHDR, SIZEOF (BitmapfileHeader), & DWWRITTEN, NULL); // Write the setup file Writefile ( FH, (LPSTR) LPBI, DWDIBSIZE, & DWWRITTEN, NULL); / / Clear GlobalUnlock (HDIB); GlobalFree (fH); Return True;} Save the bitbobject function before the bitbobject function, through the getObject function GetDibits acquires bitmap image scan data, populates BitmapFileHeader; BitmapInfoHeader; then writes the bitmap file head Writefile (FH, (LPSTR) & BMFHDR, SIZEOF (BitmapfileHeader), & dwwritten, NULL); Write the setup file The rest of the content Writefile (FH, (LPSTR) LPBI, DWDIBSIZE, & DWWRITTEN, NULL; with file head bits The order of the map information bit image is stored. In front of the three COM component interface, we created the device context in the program. The input text is calculated and outputted the bitmap file of the specified file name. In this design, we use the JPEG compressed format storage file. The way to reduce network transmission time, because the discussion of JPEG compression has exceeded the scope of this article, so there is no further details here. In order to make other languages, we release this program in a COM component, which can be called for VB, Delphi, PB, ASP and other programs. The design method of COM components is given below, and the creation of general COM components and compiles exceeding this article. Therefore, it is no longer explained. Qing plus method stdmethod (/ * [out, retval) (/ * [out, retval] * / long * pval); LTVALUE (500)] Long Lweight, [IN, OPTIONAL, DEFAULTVALUE (0)] long L3D); and stdmethod OUTIMG) (BSTR BSTRFILENAME, long ldelfile); implementation of processing files to be saved as images and outputs images to user browsers.

Codes are as follows: STDMETHODIMP CAspImage :: OutImgFromText (BSTR bstrFilePath, BSTR bstrText, BSTR bstrBgImg, long lCSet, BSTR bstrFont, long lWidth, long lHeight, long lLeft, long lTop, long llfHeight, long lWeight, long l3D) {CImg img; try {if (0 == img.OutImgFromText (bstrFilePath, bstrText, bstrBgImg, lCSet, bstrFont, lWidth, lHeight, lLeft, lTop, llfHeight, lWeight, l3D)) {return S_OK;} else {return S_FALSE;}} catch ( ...) {return s_false;} Return S_ok; / ** /} Some processing code We encapsulated in the CIMG class, which has been described earlier, just simply call it. STDMETHODIMP CAspImage :: OutTextImg (long * pVal) {HRESULT hr = OutImgFromText (bstrFilePath, bstrText, bstrBgImg, lCSet, bstrFont, lWidth, lHeight, lLeft, lTop, llfHeight, lWeight, l3D); if (SUCCEEDED (hr)) * pVal = 0; Else * pval = -1; return s_ok;} OutTextImg function is only simply calling the OutImgFromText interface.

STDMETHODIMP CAspImage :: OutImg (BSTR bstrFileName, long lDelFile) {// TODO: Add your implementation code here _variant_t vReturnBuffer; LPSAFEARRAY psaFile; HANDLE hFile; DWORD dwSizeOfFile; DWORD dwNumberOfBytesRead; BOOL bResult; unsigned char * pReturnBuffer = NULL; long k; HRESULT hr = S_OK; // Create file in this case only OPENS an existing file hFile = :: CreateFile (bstrFileName, // name of the fileGENERIC_READ, // desired accessFILE_SHARE_READ, (or fails // if the file does not exist!) // shared accessNULL, // security attributesOPEN_EXISTING, // creation disposition - open only if existing FILE_FLAG_SEQUENTIAL_SCAN, // flag attributesNULL);! if (hFile == INVALID_HANDLE_VALUE) {return E_FAIL;} dwSizeOfFile = :: hFile GetFileSize (, NULL) ; if (dwSizeOfFile == 0xFFFFFFFF) {return E_FAIL;} pReturnBuffer = new unsigned char [dwSizeOfFile]; // Get the binary content of the filebResult = :: ReadFile (hFile, pReturnBuffer, dwSizeOfFile, & dwNumberOfBytesRead, NULL); if (FALSE == BRESULT) {RETURN E_FAIL;} PS aFile = :: SafeArrayCreateVector (VT_UI1, 0, dwSizeOfFile); if (psaFile!) {return E_FAIL;} // Fill in the SAFEARRAY with the binary content of the filefor (k = 0; k <(int) dwSizeOfFile; k ) {if (FAILED (:: SafeArrayPutElement (psaFile, & k, & pReturnBuffer [k]))) {return E_FAIL;}} vReturnBuffer.vt = VT_ARRAY | VT_UI1; V_ARRAY (& vReturnBuffer) = psaFile; m_piResponse-> BinaryWrite (vReturnBuffer); if (PRETURNBUFFER) DELETE [] PRETURNBUFFER; / / _VARIANT_T VOUT ("Outimg Test ................."); // m_piresponse-> write (Vout);:::: : CloseHandle (HFILE); if (ldelfile! = 0) :: deletefile (bstrfilename); RETURN SUCCEEDED (HR)? S_OK: E_FAIL; RETURN S_OK;

} We use m_piresponse-> binarywrite (vreturnbuffer) for this interface; forward the image data read into memory to the user browser. In addition, in order to flexibly change the image font, size, character set and image length width, we have to add the following properties to the component. STDMETHOD (/ * [out, retval] * / bool * pval); stdmethod (/ * [in] * / bool newval); stdmethod (GET_L3D) (/ * [out, retval] * / long * pval); stdmethod (/ * [in] * / long newval); stdmethod (/ * [out, retval) (/ * pval); stdmethod (PUT_LWEIGHT) (/ * [in] * / long newval); stdmethod (/ * [out, retval] * / long * pval); stdmethod (/ * [in] * / long newval); stdmethod (/ * [OUT, RETVAL] * / long * pval); stdmethod (/ * [in] * / long newval); stdmethod (/ * [out, retval] * / long * pval); stdmethod (PUT_LCSET) (/ * [in] * / long newval); StdMethod (PUT_BSTRBGIMG); stdmethod (PUT_BSTRFILEPATH) (/ * [in] * / bstr newval); stdmethod (PUT_BSTRFONT) (/ * [ IN] * / bstr newval); stdmethod (/ * [in] * / bstr newval); stdmethod (/ * [out, retval) (/ * pval); stdmethod (put_llfheight) (/ * [in] * / long newval); stdmethod (/ * [out, return); stdmethod (PUT_LHEIGHT) (/ * [in] * / long newval); stdmethod (GET_LWIDTH) (/ * [OUT, RET Val] * / long * pval); stdmethod (/ * [in] * / long newval); achieve custom image length, wide, font size, font name, and other properties. Such as: Set the image text STDMETHODIMP CAspImage :: put_bstrText (BSTR newVal) {bstrText = newVal; return S_OK;} is provided an image height STDMETHODIMP CAspImage :: put_lHeight (long newVal) {lHeight = newVal; return S_OK;} This program uses four component ASP Output images to the user browser first registering this component on the server before use, Method: Copy xtaspimage.dll to the system directory, generally c: / winnt / system32 run -> regsvr32 xtaspimage.dll If the installation is successful, there will be successful tips . This process is only used once.

Here is to call the method in ASP 1. 2. 3. < ! - # include file = "config / dbconn.asp" -> 4. <% a) DIM TEACHID, PAGETEXTLEN, PAGE, SUMPAGE, BODYLEN, TEMPLATEBODY, WIDTH, HEIGHT, FHEIGHT, SENDSTRB Teachid = Int (Request " "TeachID")) C) PageTextlen = Int (Request ("PageTextlen")) D) IF PageTextlen <= 0 THENI. PageTextlen = 300E) END IF F) Page = Int (Request ("Page")) G) SET RS = Server.createObject ("AdoDb.Recordset") h) SQL = "SELECT * from article where id =" & teachidi) rs.open SQL, CONN, 1, 1 J) IF NOT = rEF THENI. TeachingBody = RS ( "Content") & considendStrk) Elsei. Response.write ("Record does not exist") II. Rs.closeiii. Set rs = Nothingiv. Conn.closev. Set conn = Nothingvi. Response.Endl) end if m) Bodylen = LEN (Teachingbody) n) Sumpage = getMaxpagenum (Bodylen, PageTextlen) O) DIM SPAGETEXT P) IF Page> = Sumpage Theni. Page = SumpageQ) End IF R) IF Page <= 0 THENI. Page = 1S) End IF T) SPAGETEXT = MID (TeachingBody, (Page-1) * PageTextlen 1, PageTextle n) u) DIM SFONTV) SFONT = Request ("FontFace") W) DIM FileName X) filename = getTempFileName (Server.MAppath ("TMP"), "Xtimg_", "JPG") Y) On Error ResMe Nextz) SET Obj = server.createObject ("xtaspimage.aspimage") AA) response.clearb) if Err.Number <> 0 Theni. Response.write "first installs the letter to the day aspimage component!" II. Response.endcc) Endiff DD) obj.bstrfilepath = filenameee) Obj.lheight = int (Request ("Height")) ff) obj.lwidth = int (Request ("width"

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

New Post(0)