|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ImageFileWriter | Line # 30 | 1 | 0% | 1 | 0 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| No Tests | |||
| 1 | /* | |
| 2 | * Created on May 1, 2009 | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | |
| 5 | * the License. You may obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | * | |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | |
| 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 11 | * specific language governing permissions and limitations under the License. | |
| 12 | * | |
| 13 | * Copyright @2009-2010 the original author or authors. | |
| 14 | */ | |
| 15 | package org.fest.swing.image; | |
| 16 | ||
| 17 | import static org.fest.swing.image.ImageFileExtensions.PNG; | |
| 18 | import static org.fest.util.Files.newFile; | |
| 19 | ||
| 20 | import java.awt.image.BufferedImage; | |
| 21 | import java.io.IOException; | |
| 22 | ||
| 23 | import javax.imageio.ImageIO; | |
| 24 | ||
| 25 | /** | |
| 26 | * Understands how to write an image as a file in the file system. | |
| 27 | * | |
| 28 | * @author Alex Ruiz | |
| 29 | */ | |
| 30 | public class ImageFileWriter { | |
| 31 | ||
| 32 | /** | |
| 33 | * Writes an image as a PNG file to the file system. | |
| 34 | * If there is already a <code>File</code> present, its contents are discarded. | |
| 35 | * @param image a <code>BufferedImage</code> to be written. | |
| 36 | * @param filePath the path of the image file to create. | |
| 37 | * @return <code>false</code> if the image could not be saved. | |
| 38 | * @exception IOException if an error occurs during writing. | |
| 39 | */ | |
| 40 | 3 |
public boolean writeAsPng(BufferedImage image, String filePath) throws IOException { |
| 41 | 3 | return ImageIO.write(image, PNG, newFile(filePath)); |
| 42 | } | |
| 43 | } | |
|
||||||||||||