Java實(shí)現(xiàn)將png格式圖片轉(zhuǎn)換成jpg格式圖片的方法【測試可用】
本文實(shí)例講述了Java實(shí)現(xiàn)將png格式圖片轉(zhuǎn)換成jpg格式圖片的方法。分享給大家供大家參考,具體如下:
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ConvertImageFile {
public static void main(String[] args) {
BufferedImage bufferedImage;
try {
// read image file
bufferedImage = ImageIO.read(new File("c:\\java.png"));
// create a blank, RGB, same width and height, and a white
// background
BufferedImage newBufferedImage = new BufferedImage(
bufferedImage.getWidth(), bufferedImage.getHeight(),
BufferedImage.TYPE_INT_RGB);
// TYPE_INT_RGB:創(chuàng)建一個RBG圖像,24位深度,成功將32位圖轉(zhuǎn)化成24位
newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0,
Color.WHITE, null);
// write to jpeg file
ImageIO.write(newBufferedImage, "jpg", new File("c:\\java.jpg"));
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}
}
}
PS:這里再為大家推薦幾款圖片處理相關(guān)在線工具供大家參考:
在線圖片格式轉(zhuǎn)換(jpg/bmp/gif/png)工具:
http://tools.jb51.net/aideddesign/picext
在線圖片裁剪/生成工具:
http://tools.jb51.net/aideddesign/imgcut
ICO圖標(biāo)在線生成工具:
http://tools.jb51.net/aideddesign/ico_img
在線低多邊形圖形生成工具:
http://tools.jb51.net/aideddesign/img_lowpoly
更多java相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Java圖片操作技巧匯總》、《java日期與時間操作技巧匯總》、《Java操作DOM節(jié)點(diǎn)技巧總結(jié)》、《Java文件與目錄操作技巧匯總》及《Java數(shù)據(jù)結(jié)構(gòu)與算法教程》。
希望本文所述對大家java程序設(shè)計有所幫助。
相關(guān)文章
springboot實(shí)現(xiàn)文件上傳步驟解析
這篇文章主要介紹了springboot實(shí)現(xiàn)文件上傳步驟解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-12-12
RabbitMQ消費(fèi)者限流實(shí)現(xiàn)消息處理優(yōu)化
這篇文章主要介紹了RabbitMQ消費(fèi)者限流實(shí)現(xiàn)消息處理優(yōu)化,消費(fèi)者限流是用于消費(fèi)者每次獲取消息時限制條數(shù),注意前提是手動確認(rèn)模式,并且在手動確認(rèn)后才能獲取到消息,感興趣想要詳細(xì)了解可以參考下文2023-05-05
Java設(shè)計模式之裝飾模式(Decorator模式)介紹
這篇文章主要介紹了Java設(shè)計模式之裝飾模式(Decorator模式)介紹,本文講解了為什么使用Decorator、如何使用裝飾模式、Jive中的Decorator實(shí)現(xiàn)等內(nèi)容,需要的朋友可以參考下2015-03-03

