⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ofimage.java

📁 现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为project的文件里.安装好后用bluej打开peoject的例子,可以进行你想要的任何变化.同时可以了解大量的源码
💻 JAVA
字号:
import java.awt.*;import java.awt.image.*;import javax.swing.*;/** * OFImage is a class that defines an image in OF (Objects First) format. *  * @author  Michael Kolling and David J. Barnes * @version 1.1 */public class OFImage extends BufferedImage{    /**     * Create an OFImage copied from a BufferedImage.     * @param image The image to copy.     */    public OFImage(BufferedImage image)    {         super(image.getColorModel(), image.copyData(null),                image.isAlphaPremultiplied(), null);    }    /**     * Create an OFImage with specified size and unspecified content.     * @param width The width of the image.     * @param height The height of the image.     */    public OFImage(int width, int height)    {        super(width, height, TYPE_INT_RGB);    }    /**     * Set a given pixel of this image to a specified color. The     * color is represented as an (r,g,b) value.     * @param x The x position of the pixel.     * @param y The y position of the pixel.     * @param col The color of the pixel.     */    public void setPixel(int x, int y, Color col)    {        int pixel = col.getRGB();        setRGB(x, y, pixel);    }        /**     * Get the color value at a specified pixel position.     * @param x The x position of the pixel.     * @param y The y position of the pixel.     * @return The color of the pixel at the given position.     */    public Color getPixel(int x, int y)    {        int pixel = getRGB(x, y);        return new Color(pixel);    }    /**     * Make this image a bit darker.     */    public void darker()    {        int height = getHeight();        int width = getWidth();        for(int y = 0; y < height; y++) {            for(int x = 0; x < width; x++) {                setPixel(x, y, getPixel(x, y).darker());            }        }    }    /**     * Make this image a bit lighter.     */    public void lighter()    {        int height = getHeight();        int width = getWidth();        for(int y = 0; y < height; y++) {            for(int x = 0; x < width; x++) {                setPixel(x, y, getPixel(x, y).brighter());            }        }    }    /**     * Perform a three level threshold operation.     * That is: repaint the image with only three color values:     *          white, gray, and black.     */    public void threshold()    {        int height = getHeight();        int width = getWidth();        for(int y = 0; y < height; y++) {            for(int x = 0; x < width; x++) {                Color pixel = getPixel(x, y);                int brightness = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;                if(brightness <= 85) {                    setPixel(x, y, Color.BLACK);                }                else if(brightness <= 170) {                    setPixel(x, y, Color.GRAY);                }                else {                    setPixel(x, y, Color.WHITE);                }            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -