1. 程式人生 > >e680. 使三元色圖像變明變暗

e680. 使三元色圖像變明變暗

ken lin esc body tegra nbsp width pre lpad

This example demonstrates how to brighten or darken an RGB buffered image by scaling the red, green, and blue values in the image.

    // To create a buffered image, see e666 創建緩沖圖像
    
    // Brighten the image by 30%
    float scaleFactor = 1.3f;
    RescaleOp op = new RescaleOp(scaleFactor, 0, null);
    bufferedImage
= op.filter(bufferedImage, null); // Darken the image by 10% scaleFactor = .9f; op = new RescaleOp(scaleFactor, 0, null); bufferedImage = op.filter(bufferedImage, null);

If the image is not an RGB image, the following code converts a non-RGB image to an RGB buffered image:

    // Get non-RGB image
    Image image = new ImageIcon("image.gif"
).getImage(); // Create an RGB buffered image BufferedImage bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); // Copy non-RGB image to the RGB buffered image Graphics2D g = bimage.createGraphics(); g.drawImage(image, 0, 0, null); g.dispose();

Related Example

e680. 使三元色圖像變明變暗