To reduce the size of a file, a similar small image is often merged into a file. When the program is actually drawing, only a part of the image in the file can be displayed as needed. The setclip method in graphics implements this function.
The setclip method is used to display only a part of the content on the screen, so that the content of the image is displayed exactly in this part.
The setclip method is to set the "Perspective hole" on the screen, only the image content in the hole is displayed.
The setclip method is described as follows:
Public void setclip (int x, int y, int width, int height)
Where:
X -- the X coordinate in the upper left corner of the rectangle that can be displayed
Y -- y coordinate of the upper left corner of the display area
Width -- the width of the rectangle
Height -- giant height
Example:
G. setclip (10, 20, 20, 30 );
G. drawimage (image, 10, 20, graphics. Left | graphics. Top );
Only the starting position, height 30, width 20, and other parts of the image represented by the image object are displayed.
Note: After using setclip, You need to restore the default settings of the system so that the entire screen can be displayed:
G. setclip (0, 0, this. getwidth (), this. getheight ());
[Reprint] the use of the small tip: setclip Method