e680. 使三元色图像变明变暗

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
posted @ 2018-09-02 21:42  borter  阅读(115)  评论(0编辑  收藏  举报