Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 18 產生驗證碼. No Cache 防止在 JSP 或 SERVLET 中的輸出不被 BROWSER 保存在 CACHE 中.

Similar presentations


Presentation on theme: "Chapter 18 產生驗證碼. No Cache 防止在 JSP 或 SERVLET 中的輸出不被 BROWSER 保存在 CACHE 中."— Presentation transcript:

1 Chapter 18 產生驗證碼

2 No Cache 防止在 JSP 或 SERVLET 中的輸出不被 BROWSER 保存在 CACHE 中

3 BufferedImage java.awt.image.BufferedImage The BufferedImage subclass describes an Image with an accessible buffer of image data.Image public BufferedImage(int width, int height, int imageType) Constructs a BufferedImage of one of the predefined image types.

4 BufferedImage TYPE_INT_RGB public static final int TYPE_INT_RGB Represents an image with 8-bit RGB color components packed into integer pixels.

5 BufferedImage getGraphics() This method returns a Graphics2D, but is here for backwards compatibility. createGraphics is more convenient, since it is declared to return a Graphics2D.Graphics2D createGraphics createGraphics() Creates a Graphics2D, which can be used to draw into this BufferedImage.

6 Graphics java.awt.Graphics The Graphics class is the abstract base class for all graphics contexts that allow an application to draw onto components that are realized on various devices, as well as onto off-screen images.

7 Graphics setColor(Color c)Color Sets this graphics context's current color to the specified color. All subsequent graphics operations using this graphics context use this specified color.

8 Graphics fillRect(int x, int y, int width, int height) Fills the specified rectangle. The left and right edges of the rectangle are at x and x + width - 1. The top and bottom edges are at y and y + height - 1. The resulting rectangle covers an area width pixels wide by height pixels tall. The rectangle is filled using the graphics context's current color.

9 Graphics setFont(Font font)Font Sets this graphics context's font to the specified font. All subsequent text operations using this graphics context use this font.

10 Graphics drawLine(int x1, int y1, int x2, int y2) Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.

11 Graphics drawString(String str, int x, int y)String Draws the text given by the specified string, using this graphics context's current font and color. The baseline of the leftmost character is at position (x, y) in this graphics context's coordinate system.

12 Graphics dispose() Disposes of this graphics context and releases any system resources that it is using. A Graphics object cannot be used after dispose has been called.

13 Color Java.awt.Color The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary color spaces identified by a ColorSpace.ColorSpace Color(float r, float g, float b)

14 Font Java.awt.Font The Font class represents fonts, which are used to render text in a visible way. Font(String name, int style, int size)String

15 Random java.util.Random An instance of this class is used to generate a stream of pseudorandom numbers. The class uses a 48-bit seed, which is modified using a linear congruential formula.

16 Random Random() Creates a new random number generator. This constructor sets the seed of the random number generator to a value very likely to be distinct from any other invocation of this constructor.

17 Random nextInt() Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence. The general contract of nextInt is that one int value is pseudorandomly generated and returned. All 2 32 possible int values are produced with (approximately) equal probability.

18 Random nextInt(int n) Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. The general contract of nextInt is that one int value in the specified range is pseudorandomly generated and returned. All n possible int values are produced with (approximately) equal probability.

19 ImageIO javax.imageio.ImageIO lets you save and restore Images to disk in a platform independent format. With ImageIO, instead of Image you use BufferedImage which is a subclass of Image, and can thus be used in any of the familiar tools that work with Images.

20 ImageIO Loading a BufferedImage from a file BufferedImage image = ImageIO.read( new File( "rabbit.jpg" ) ); Saving a BufferedImage to a file ImageIO.write( aBufferedImage, "jpeg" /* "png" "jpeg" format desired, no "gif" yet. */, new File ( "snap.jpg" ) /* target */ );

21 getOutputStream() response.getOutputStream() Returns a ServletOutputStream suitable for writing binary data in the response. The servlet container does not encode the binary data.ServletOutputStream


Download ppt "Chapter 18 產生驗證碼. No Cache 防止在 JSP 或 SERVLET 中的輸出不被 BROWSER 保存在 CACHE 中."

Similar presentations


Ads by Google