---
title: " java另存图片底色变黑问题"
author: "lu_tan"
date: "2014-07-16T11:32:18Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2014-07-16T11:32:18Z"
id: 2092669
url: "https://lu-tan.iteye.com/blog/2092669"
---

BufferedImage bufferImage;
File outputFile = null;
try{
     Image image = ImageIO.red(new File("c:\\pic\\aa.jpeg"));
     int width = image.getWidth(null);
     int height = image.getHeight(null);
     bufferImage= new BufferedImage (width,height,BufferedImage.TYPE_INT_RGB);
       bufferImage.getGraphics().drawImage(image,0,0,width,height,image.getGraphics().getColor(),null);//设置底色
 
       outputFile = new File("c:\\pic\\bb.jpeg");
       if(!outputFile.exists())
            outputFile.mkdirs();
       ImageIO.write(bufferImage,"jpeg",outputFile);
}catch(IOException e){
     e.printStackTrace();
}