目录
- 1 问题
- 2 实现
1 问题
Java 实现灰度图转真彩图
将以上的图片,jpg png 都可以,转为有颜色的
2 实现
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.io.File;
public class DatUtils {
public static void main(String[] args) {
File file = new File("C:\\Users\\\\55\\1.jpg");
File file1 = new File("C:\\Users\\\\55");
System.out.println(picGrayToColour(file.getPath(),file1.getPath(),"33.jpg"));
}
/**
* 灰度图转真彩图
* @param path-灰度图路径
* @param outPath-真彩图输出路径
*/
public static boolean picGrayToColour(String path, String outPath, String picName){
try {
File file = new File(path);
BufferedImage bufferedImage = ImageIO.read(file);
BufferedImage bImage=new BufferedImage(bufferedImage.getWidth(),bufferedImage.getHeight(),BufferedImage.TYPE_4BYTE_ABGR);
Raster data = bufferedImage.getData();
for