From http://hpping.hdut.com/info/113/46284111.aspx
1. Add watermarks to images
// Instantiate the component
Aspjpeglib. iaspjpeg objjpeg = new aspjpeglib. aspjpeg ();
// Open source image files
Objjpeg. Open (server. mappath ("AAA. jpg "));
// Add watermark text
Objjpeg. Canvas. Font. Color = 0xff0000; // watermark font color
Objjpeg. Canvas. Font. Family = "Courier New"; // watermark font
Objjpeg. Canvas. Font. size = 14; // watermark font size
Objjpeg. Canvas. Font. Bold = 1; // whether it is bold. Use true (1) or false (0) in bold)
Objjpeg. Canvas. Font. Quality = 4; // Quality
Objjpeg. Canvas. Font. bkmode = "Opaque"; // specifies the font background color, which is transparent (opaque)
Objjpeg. Canvas. Print (10, 10, "Copyright (c) hdut. com", missing. Value); // watermark text. Two digits 10 are the XY coordinates of the watermark.
Objjpeg. Save (server. mappath ("aaa_water.jpg "));
Objjpeg = NULL; // log out of the component and release the resource.
========================================================== ========================================================== ====================
Ii. Generating thumbnails
// Instantiate the component
Aspjpeglib. iaspjpeg objjpeg = new aspjpeglib. aspjpeg ();
// Open source image files
Objjpeg. Open (server. mappath ("AAA. jpg "));
// Perform the 50% operation on the Image
Objjpeg. width = objjpeg. originalwidth/2;
Objjpeg. Height = objjpeg. originalheight/2;
// Sharpen the image if necessary
Objjpeg. Sharpen (1,130 );
Objjpeg. Save (server. mappath ("aaa_small.jpg"); // generates the thumbnail position and name.
Objjpeg = NULL; // log out of the component and release the resource.
========================================================== ========================================================== ====================
3. Security Code
The security code is similar to watermarking. Many friends asked me for details.CodeHere, I will write about the technology and share it with you. I will not tell anyone about it. Haha.
Generate a picture of the security code. Of course, you need to prepare a background image in advance.
// Obtain the 4-digit Verification Code
Random RD = new random ();
Session ["random_num"] = RD. netx (1000,9999 );
// Instantiate the component
Aspjpeglib. iaspjpeg objjpeg = new aspjpeglib. aspjpeg ();
// Open the background image file
Objjpeg. Open (server. mappath ("back. jpg "));
JPEG. Canvas. Font. Color = & h006699
JPEG. Canvas. Font. Family = "Arial black"
JPEG. Canvas. Font. Bold = false
JPEG. Canvas. printtext 0,-2, random_num
JPEG. Save (server. mappath ("random_index.jpg") // save
Do it yourself. Haha.
========================================================== ========================================================== ====================
Iv. Image Cutting
For a long time, people who do not know about aspjpeg think that they cannot use it for cutting.
There is actually a method like this: crop (x1, Y1, X2, Y2)
Returns the X coordinate in the upper left corner of the rectangular shape, and the Y coordinate in the lower right corner of the Y coordinate.
// Instantiate the component
Aspjpeglib. iaspjpeg objjpeg = new aspjpeglib. aspjpeg ();
// Open the image file
Objjpeg. Open (server. mappath ("AAA. jpg "));
Objjpeg. width = 70
Objjpeg. Height = objjpeg. originalheight * 70;
Objjpeg. Crop (, 52); // The start of the cut operation is to remove the lower part of more than 52 pixels.
Objjpeg. Save (server. mappath ("aaa_1.gif"); // save
How is it? It's easy.
========================================================== ========================================================== ====================
5. Image Merging
We need to add the logoimage to the aaa.jpg image.
In fact, the image merging method can also be used for dynamic watermarking.
// Instantiate the component
Aspjpeglib. iaspjpeg objjpeg = new aspjpeglib. aspjpeg ();
// Open the image file
Objjpeg. Open (server. mappath ("AAA. jpg "));
// Instantiate the logo component
Aspjpeglib. iaspjpeg logo = new aspjpeglib. aspjpeg ();
// Open the logo image file
Logo. Open (server. mappath ("logo. jpg "));
Logo. width = 70;
Logo. Height = logo. Width * logo. originalheight/logo. originalwidth; // redefine the size.
// Merge the logo into the image
Objjpeg. drawimage (0, 0, logo );
Note:
Drawimage (int x, int y, aspw.lib. aspjpeg image, object opacity, object transpcolor, object deviation)
X: X coordinate
Y: Y coordinate
Image: Image
Opacity: The default value is 1. It is transparent and can be set to 0 or 1.
Transpcolor: transparent color, hexadecimal
Deviation: transparent value (0-255). The default value is 0.
========================================================== ========================================================== ====================
We recommend that you use objjpeg. Canvas. drawpng (X, Y, server. mappath ("/images/hhdut.png "));
This will not only be faster, but will not cause errors.
Vi. Database Support
// Instantiate the component
Aspjpeglib. iaspjpeg objjpeg = new aspjpeglib. aspjpeg ();
// Open the image data source
Object OBJ = edata. getdata ("Select images from IMG where id = 12 ");
Objjpeg. openbinary (OBJ );
// Display the image
Objjpeg. sendbinary (missing. value );
The output method of sendbinary is used here. Of course, you can save and modify the aaa.jpg file before entering it. I personally do not like to use the sendbinary method, which is prone to errors when the network speed is slow. The speed is not very good. Haha.
========================================================== ========================================================== ====================
7. More Methods
// Draw a straight line
Canvas. Line (left, top, right, bottom );
// Draw an ellipse
Canvas. ellipse (left, top, right, bottom );
// Draw a circle
Canvas. Circle (X, Y, radius );
// Draw a rectangle with code on it
Canvas. Bar (left, top, right, bottom );
// Text shadow color
Canvas. Font. shadowcolor;
// Shadow X coordinate settings
Int64 canvas. Font. shadowxoffset;
// Y coordinate settings
Int64 canvas. Font. shadowyoffset;
// Text background
String canvas. Font. bkmode;
========================================================== ======================
Related file downloads: http://files.cnblogs.com/wangpei/AspJpegDLL.rar