开发者社区> 问答> 正文

java实现读取一张图片给这张图片整体颜色加深

比如我有张图片,图片整体颜色很淡,这时候我需要整体加深颜色,java有没有什么办法

展开
收起
蛮大人123 2016-02-21 10:38:48 5011 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    public static void resize(String filePath, int height, int width, boolean bb) {
            try {
                double ratio = 0; //缩放比例    
                File f = new File(filePath);   
                BufferedImage bi = ImageIO.read(f);   
                Image itemp = bi.getScaledInstance(width, height, BufferedImage.SCALE_SMOOTH);   
                //计算比例   
                if ((bi.getHeight() > height) || (bi.getWidth() > width)) {   
                    if (bi.getHeight() > bi.getWidth()) {   
                        ratio = (new Integer(height)).doubleValue() / bi.getHeight();   
                    } else {   
                        ratio = (new Integer(width)).doubleValue() / bi.getWidth();   
                    }   
                    AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(ratio, ratio), null);   
                    itemp = op.filter(bi, null);   
                }   
                if (bb) {   
                    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);   
                    Graphics2D g = image.createGraphics();   
                    g.setColor(Color.white);   
                    g.fillRect(0, 0, width, height);   
                    if (width == itemp.getWidth(null))   
                        g.drawImage(itemp, 0, (height - itemp.getHeight(null)) / 2, itemp.getWidth(null), itemp.getHeight(null), Color.white, null);   
                    else  
                        g.drawImage(itemp, (width - itemp.getWidth(null)) / 2, 0, itemp.getWidth(null), itemp.getHeight(null), Color.white, null);   
                    g.dispose();   
                    itemp = image;   
                }
                ImageIO.write((BufferedImage) itemp, "jpg", f);   
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    2019-07-17 18:45:46
    赞同 1 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载