码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-09-03 00:01:08      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:actor   gre   strong   example   creat   lsp   buffere   draw   factor   

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. 使三元色图像变明变暗

标签:actor   gre   strong   example   creat   lsp   buffere   draw   factor   

原文地址:https://www.cnblogs.com/borter/p/9575496.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!