Java實現(xiàn)將png格式圖片轉(zhuǎn)換成jpg格式圖片的方法【測試可用】
本文實例講述了Java實現(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圖標在線生成工具:
http://tools.jb51.net/aideddesign/ico_img
在線低多邊形圖形生成工具:
http://tools.jb51.net/aideddesign/img_lowpoly
更多java相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Java圖片操作技巧匯總》、《java日期與時間操作技巧匯總》、《Java操作DOM節(jié)點技巧總結(jié)》、《Java文件與目錄操作技巧匯總》及《Java數(shù)據(jù)結(jié)構(gòu)與算法教程》。
希望本文所述對大家java程序設(shè)計有所幫助。
相關(guān)文章
RabbitMQ消費者限流實現(xiàn)消息處理優(yōu)化
這篇文章主要介紹了RabbitMQ消費者限流實現(xiàn)消息處理優(yōu)化,消費者限流是用于消費者每次獲取消息時限制條數(shù),注意前提是手動確認模式,并且在手動確認后才能獲取到消息,感興趣想要詳細了解可以參考下文2023-05-05Java設(shè)計模式之裝飾模式(Decorator模式)介紹
這篇文章主要介紹了Java設(shè)計模式之裝飾模式(Decorator模式)介紹,本文講解了為什么使用Decorator、如何使用裝飾模式、Jive中的Decorator實現(xiàn)等內(nèi)容,需要的朋友可以參考下2015-03-03