关于通过java实现图片格式的转换
2011-12-12 17:53:49萨***
关于通过java实现图片格式的转换关于通过java实现图片格式的转换:
import .*; import t.*; import age.*;
import t.Gr?
最佳回答
SCALE_DEFAULT); BufferedImage tag = new BufferedImage(width, height, BufferedImage。TYPE_INT_RGB); Graphics g = tGraphics(); g。
drawImage(image, 0, 0, null); // 绘制缩小后的图 g。dispose(); ImageIO。write(tag, "JPEG", new File(result));// 输出到文件流 } catch (IOException e) { intStackTrace(); } } /** * 图像切割 * @param srcImageFile源图像地址 * @param descDir切片目标文件夹 * @param destWidth目标切片宽度 * @param destHeight目标切片高度 */ public static void cut(String srcImageFile, String descDir, int destWidth, int destHeight) { try { Image img; ImageFilter cropFilter; // 读取源图像 BufferedImage bi = ad(new File(srcImageFile)); int srcWidth = tHeight(); // 源图宽度 int srcHeight = tWidth(); // 源图高度 if (srcWidth > destWidth && srcHeight > destHeight) { Image image = tScaledInstance(srcWidth, srcHeight, Image。
SCALE_DEFAULT); destWidth = 200; // 切片宽度 destHeight = 150; // 切片高度 int cols = 0; // 切片横向数量 int rows = 0; // 切片纵向数量 // 计算切片的横向和纵向数量 if (srcWidth % destWidth == 0) { cols = srcWidth / destWidth; } else { cols = (int) Math。
floor(srcWidth / destWidth) + 1; } if (srcHeight % destHeight == 0) { rows = srcHeight / destHeight; } else { rows = (int) Math。
floor(srcHeight / destHeight) + 1; } // 循环建立切片 // 改进的想法:是否可用多线程加快切割速度 for (int i = 0; i JPG GIF->PNG PNG->JPG PNG->GIF(X) public static void convert(String source, String result) { try { File f = new File(source); nRead(); nWrite(); BufferedImage src = ad(f); ImageIO。
write(src, "JPG", new File(result)); } catch (Exception e) { // TODO Auto-generated catch block intStackTrace(); } } // 彩色转为黑白 public static void gray(String source, String result) { try { BufferedImage src = ad(new File(source)); ColorSpace cs = tInstance(ColorSpace。
CS_GRAY); ColorConvertOp op = new ColorConvertOp(cs, null); src = lter(src, null); ImageIO。write(src, "JPEG", new File(result)); } catch (IOException e) { intStackTrace(); } } public static void main(String[] args) { //cut("e:/ g", "e:/t/", 200, 150); } } import 。
*; import t。*; import age。*; import t。Graphics; import lor。ColorSpace; import ageio。ImageIO; public class ImageCut { /** * 缩放图像 * @param srcImageFile源图像文件地址 * @param result缩放后的图像地址 * @param scale缩放比例 * @param flag缩放选择:true 放大; false 缩小; */ public static void scale(String srcImageFile, String result, int scale, boolean flag) { try { BufferedImage src = ad(new File(srcImageFile)); // 读入文件 int width = tWidth(); // 得到源图宽 int height = tHeight(); // 得到源图长 if (flag) {// 放大 width = width * scale; height = height * scale; } else {// 缩小 width = width / scale; height = height / scale; } Image image = tScaledInstance(width, height, Image。
SCALE_DEFAULT); BufferedImage tag = new BufferedImage(width, height, BufferedImage。TYPE_INT_RGB); Graphics g = tGraphics(); g。
drawImage(image, 0, 0, null); // 绘制缩小后的图 g。dispose(); ImageIO。write(tag, "JPEG", new File(result));// 输出到文件流 } catch (IOException e) { intStackTrace(); } } /** * 图像切割 * @param srcImageFile源图像地址 * @param descDir切片目标文件夹 * @param destWidth目标切片宽度 * @param destHeight目标切片高度 */ public static void cut(String srcImageFile, String descDir, int destWidth, int destHeight) { try { Image img; ImageFilter cropFilter; // 读取源图像 BufferedImage bi = ad(new File(srcImageFile)); int srcWidth = tHeight(); // 源图宽度 int srcHeight = tWidth(); // 源图高度 if (srcWidth > destWidth && srcHeight > destHeight) { Image image = tScaledInstance(srcWidth, srcHeight, Image。
SCALE_DEFAULT); destWidth = 200; // 切片宽度 destHeight = 150; // 切片高度 int cols = 0; // 切片横向数量 int rows = 0; // 切片纵向数量 // 计算切片的横向和纵向数量 if (srcWidth % destWidth == 0) { cols = srcWidth / destWidth; } else { cols = (int) Math。
floor(srcWidth / destWidth) + 1; } if (srcHeight % destHeight == 0) { rows = srcHeight / destHeight; } else { rows = (int) Math。
floor(srcHeight / destHeight) + 1; } // 循环建立切片 // 改进的想法:是否可用多线程加快切割速度 for (int i = 0; i JPG GIF->PNG PNG->JPG PNG->GIF(X) public static void convert(String source, String result) { try { File f = new File(source); nRead(); nWrite(); BufferedImage src = ad(f); ImageIO。
write(src, "JPG", new File(result)); } catch (Exception e) { // TODO Auto-generated catch block intStackTrace(); } } // 彩色转为黑白 public static void gray(String source, String result) { try { BufferedImage src = ad(new File(source)); ColorSpace cs = tInstance(ColorSpace。
CS_GRAY); ColorConvertOp op = new ColorConvertOp(cs, null); src = lter(src, null); ImageIO。
write(src, "JPEG", new File(result)); } catch (IOException e) { intStackTrace(); } } public static void main(String[] args) { //cut("e:/ g", "e:/t/", 200, 150); } } 。
2011-12-12 17:54:43
很赞哦! (238)
相关文章
- 如何用C语言将jpg图片转换成b
- 如何用C语言将图片由jpg转换成
- 怎么把JPG格式图片转化成二进制
- 缩略图是怎么生成的这个网站课件的
- C、C++、VC++、Java、
- C语言C++和JAVAVBVC
- HPColorLaserJet2
- Java如何实现在数据库中读取图
- 如何将exe转为txt我下了一本
- JAVA中如何将File转变成I
- 学JAVA手机游戏开发需要用到哪
- 计算机流程图中菱形框和矩形框代表
- jsp文件怎么打开啊?重装电脑后
- 海明码校验码的位置为什么不一样有
- Java变量类型间如何相互转换?
- java问题用java代码在后台
- 位图转化为CAD用什么方法最好原
- 如何将JAVA程序转化成C程序?
- abplc程序怎么拷贝到PLC内
- 求问怎么在电脑上将RAW文件转化
- 关于图片格式转换问题我把GIF的
- 如何用C语言将jpg图片转换成b
- 如何用C语言将图片由jpg转换成
- 怎么把JPG格式图片转化成二进制
- 缩略图是怎么生成的这个网站课件的
- C、C++、VC++、Java、
- C语言C++和JAVAVBVC
- HPColorLaserJet2
- Java如何实现在数据库中读取图
- 如何将exe转为txt我下了一本
- JAVA中如何将File转变成I
- 学JAVA手机游戏开发需要用到哪
- 计算机流程图中菱形框和矩形框代表
- jsp文件怎么打开啊?重装电脑后
- 海明码校验码的位置为什么不一样有
- Java变量类型间如何相互转换?
- java问题用java代码在后台
- 位图转化为CAD用什么方法最好原
- 如何将JAVA程序转化成C程序?
- abplc程序怎么拷贝到PLC内
- 求问怎么在电脑上将RAW文件转化
- 关于图片格式转换问题我把GIF的