java另存图片底色变黑问题
- 摘要:BufferedImagebufferImage;FileoutputFile=null;try{Imageimage=ImageIO.red(newFile("c:\\pic\\aa.jpeg"));intwidth=image.getWidth(null);intheight=image.getHeight(null);bufferImage=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);bufferImage
- 标签:
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();
}