- 浏览: 532787 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
宋贝贝:
您好,能麻烦您把这个包fisher.man.jce.PKCS1 ...
生成基于RSA与SM2数字证书的请求PKCS10CertificationRequest -
upset_ming:
DoubleCA的JCE实现了SM2算法的密钥协商,国密SM2 ...
生成基于RSA与SM2数字证书的请求PKCS10CertificationRequest -
stormlyf:
您好,能麻烦您把这个包fisher.man.jce.PKCS1 ...
生成基于RSA与SM2数字证书的请求PKCS10CertificationRequest -
kris_zhang:
CPU型号怎么弄?
Java获取电脑CPU个数及系统信息 -
linxinlong11007:
你好,我需要FishermanJCE,请问能发份这个包给我么? ...
生成基于RSA与SM2数字证书的请求PKCS10CertificationRequest
java缩小图片
写道
package com.velocity;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
//生成等比例高质量缩略图
public class ScaleImage {
private int width;
private int height;
private int scaleWidth;
double support = (double) 3.0;
double PI = (double) 3.14159265358978;
double[] contrib;
double[] normContrib;
double[] tmpContrib;
int startContrib, stopContrib;
int nDots;
int nHalfDots;
public static void main(String[] args) {
ScaleImage is = new ScaleImage();
try {
System.out.println("开始"+System.currentTimeMillis());
is.saveImageAsJpg("E:/2.jpg", "E:/11.jpg", 400,
300);
System.out.println("结束"+System.currentTimeMillis());
} catch (Exception e) {
e.printStackTrace();
}
}
// fromFileStr原图片地址,saveToFileStr生成缩略图地址,formatWideth生成图片宽度,formatHeight高度
public void saveImageAsJpg(String fromFileStr, String saveToFileStr,
int formatWideth, int formatHeight) throws Exception {
BufferedImage srcImage;
File saveFile = new File(saveToFileStr);
File fromFile = new File(fromFileStr);
srcImage = javax.imageio.ImageIO.read(fromFile); // construct image
int imageWideth = srcImage.getWidth(null);
int imageHeight = srcImage.getHeight(null);
int changeToWideth = 0;
int changeToHeight = 0;
if (imageWideth > 0 && imageHeight > 0) {
// flag=true;
if (imageWideth / imageHeight >= formatWideth / formatHeight) {
if (imageWideth > formatWideth) {
changeToWideth = formatWideth;
changeToHeight = (imageHeight * formatWideth) / imageWideth;
} else {
changeToWideth = imageWideth;
changeToHeight = imageHeight;
}
} else {
if (imageHeight > formatHeight) {
changeToHeight = formatHeight;
changeToWideth = (imageWideth * formatHeight) / imageHeight;
} else {
changeToWideth = imageWideth;
changeToHeight = imageHeight;
}
}
}
srcImage = imageZoomOut(srcImage, changeToWideth, changeToHeight);
ImageIO.write(srcImage, "JPEG", saveFile);
}
public BufferedImage imageZoomOut(BufferedImage srcBufferImage, int w, int h) {
width = srcBufferImage.getWidth();
height = srcBufferImage.getHeight();
scaleWidth = w;
if (DetermineResultSize(w, h) == 1) {
return srcBufferImage;
}
CalContrib();
BufferedImage pbOut = HorizontalFiltering(srcBufferImage, w);
BufferedImage pbFinalOut = VerticalFiltering(pbOut, h);
return pbFinalOut;
}
private int DetermineResultSize(int w, int h) {
double scaleH, scaleV;
scaleH = (double) w / (double) width;
scaleV = (double) h / (double) height;
// 需要判断一下scaleH,scaleV,不做放大操作
if (scaleH >= 1.0 && scaleV >= 1.0) {
return 1;
}
return 0;
} // end of DetermineResultSize()
private double Lanczos(int i, int inWidth, int outWidth, double Support) {
double x;
x = (double) i * (double) outWidth / (double) inWidth;
return Math.sin(x * PI) / (x * PI) * Math.sin(x * PI / Support)
/ (x * PI / Support);
}
private void CalContrib() {
nHalfDots = (int) ((double) width * support / (double) scaleWidth);
nDots = nHalfDots * 2 + 1;
try {
contrib = new double[nDots];
normContrib = new double[nDots];
tmpContrib = new double[nDots];
} catch (Exception e) {
System.out.println("init contrib,normContrib,tmpContrib" + e);
}
int center = nHalfDots;
contrib[center] = 1.0;
double weight = 0.0;
int i = 0;
for (i = 1; i <= center; i++) {
contrib[center + i] = Lanczos(i, width, scaleWidth, support);
weight += contrib[center + i];
}
for (i = center - 1; i >= 0; i--) {
contrib[i] = contrib[center * 2 - i];
}
weight = weight * 2 + 1.0;
for (i = 0; i <= center; i++) {
normContrib[i] = contrib[i] / weight;
}
for (i = center + 1; i < nDots; i++) {
normContrib[i] = normContrib[center * 2 - i];
}
} // end of CalContrib()
// 处理边缘
private void CalTempContrib(int start, int stop) {
double weight = 0;
int i = 0;
for (i = start; i <= stop; i++) {
weight += contrib[i];
}
for (i = start; i <= stop; i++) {
tmpContrib[i] = contrib[i] / weight;
}
} // end of CalTempContrib()
private int GetRedValue(int rgbValue) {
int temp = rgbValue & 0x00ff0000;
return temp >> 16;
}
private int GetGreenValue(int rgbValue) {
int temp = rgbValue & 0x0000ff00;
return temp >> 8;
}
private int GetBlueValue(int rgbValue) {
return rgbValue & 0x000000ff;
}
private int ComRGB(int redValue, int greenValue, int blueValue) {
return (redValue << 16) + (greenValue << 8) + blueValue;
}
// 行水平滤波
private int HorizontalFilter(BufferedImage bufImg, int startX, int stopX,
int start, int stop, int y, double[] pContrib) {
double valueRed = 0.0;
double valueGreen = 0.0;
double valueBlue = 0.0;
int valueRGB = 0;
int i, j;
for (i = startX, j = start; i <= stopX; i++, j++) {
valueRGB = bufImg.getRGB(i, y);
valueRed += GetRedValue(valueRGB) * pContrib[j];
valueGreen += GetGreenValue(valueRGB) * pContrib[j];
valueBlue += GetBlueValue(valueRGB) * pContrib[j];
}
valueRGB = ComRGB(Clip((int) valueRed), Clip((int) valueGreen),
Clip((int) valueBlue));
return valueRGB;
} // end of HorizontalFilter()
// 图片水平滤波
private BufferedImage HorizontalFiltering(BufferedImage bufImage, int iOutW) {
int dwInW = bufImage.getWidth();
int dwInH = bufImage.getHeight();
int value = 0;
BufferedImage pbOut = new BufferedImage(iOutW, dwInH,
BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < iOutW; x++) {
int startX;
int start;
int X = (int) (((double) x) * ((double) dwInW) / ((double) iOutW) + 0.5);
int y = 0;
startX = X - nHalfDots;
if (startX < 0) {
startX = 0;
start = nHalfDots - X;
} else {
start = 0;
}
int stop;
int stopX = X + nHalfDots;
if (stopX > (dwInW - 1)) {
stopX = dwInW - 1;
stop = nHalfDots + (dwInW - 1 - X);
} else {
stop = nHalfDots * 2;
}
if (start > 0 || stop < nDots - 1) {
CalTempContrib(start, stop);
for (y = 0; y < dwInH; y++) {
value = HorizontalFilter(bufImage, startX, stopX, start,
stop, y, tmpContrib);
pbOut.setRGB(x, y, value);
}
} else {
for (y = 0; y < dwInH; y++) {
value = HorizontalFilter(bufImage, startX, stopX, start,
stop, y, normContrib);
pbOut.setRGB(x, y, value);
}
}
}
return pbOut;
} // end of HorizontalFiltering()
private int VerticalFilter(BufferedImage pbInImage, int startY, int stopY,
int start, int stop, int x, double[] pContrib) {
double valueRed = 0.0;
double valueGreen = 0.0;
double valueBlue = 0.0;
int valueRGB = 0;
int i, j;
for (i = startY, j = start; i <= stopY; i++, j++) {
valueRGB = pbInImage.getRGB(x, i);
valueRed += GetRedValue(valueRGB) * pContrib[j];
valueGreen += GetGreenValue(valueRGB) * pContrib[j];
valueBlue += GetBlueValue(valueRGB) * pContrib[j];
// System.out.println(valueRed+"->"+Clip((int)valueRed)+"<-");
//
// System.out.println(valueGreen+"->"+Clip((int)valueGreen)+"<-");
// System.out.println(valueBlue+"->"+Clip((int)valueBlue)+"<-"+"-->");
}
valueRGB = ComRGB(Clip((int) valueRed), Clip((int) valueGreen),
Clip((int) valueBlue));
// System.out.println(valueRGB);
return valueRGB;
} // end of VerticalFilter()
private BufferedImage VerticalFiltering(BufferedImage pbImage, int iOutH) {
int iW = pbImage.getWidth();
int iH = pbImage.getHeight();
int value = 0;
BufferedImage pbOut = new BufferedImage(iW, iOutH,
BufferedImage.TYPE_INT_RGB);
for (int y = 0; y < iOutH; y++) {
int startY;
int start;
int Y = (int) (((double) y) * ((double) iH) / ((double) iOutH) + 0.5);
startY = Y - nHalfDots;
if (startY < 0) {
startY = 0;
start = nHalfDots - Y;
} else {
start = 0;
}
int stop;
int stopY = Y + nHalfDots;
if (stopY > (int) (iH - 1)) {
stopY = iH - 1;
stop = nHalfDots + (iH - 1 - Y);
} else {
stop = nHalfDots * 2;
}
if (start > 0 || stop < nDots - 1) {
CalTempContrib(start, stop);
for (int x = 0; x < iW; x++) {
value = VerticalFilter(pbImage, startY, stopY, start, stop,
x, tmpContrib);
pbOut.setRGB(x, y, value);
}
} else {
for (int x = 0; x < iW; x++) {
value = VerticalFilter(pbImage, startY, stopY, start, stop,
x, normContrib);
pbOut.setRGB(x, y, value);
}
}
}
return pbOut;
} // end of VerticalFiltering()
int Clip(int x) {
if (x < 0)
return 0;
if (x > 255)
return 255;
return x;
}
}
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
//生成等比例高质量缩略图
public class ScaleImage {
private int width;
private int height;
private int scaleWidth;
double support = (double) 3.0;
double PI = (double) 3.14159265358978;
double[] contrib;
double[] normContrib;
double[] tmpContrib;
int startContrib, stopContrib;
int nDots;
int nHalfDots;
public static void main(String[] args) {
ScaleImage is = new ScaleImage();
try {
System.out.println("开始"+System.currentTimeMillis());
is.saveImageAsJpg("E:/2.jpg", "E:/11.jpg", 400,
300);
System.out.println("结束"+System.currentTimeMillis());
} catch (Exception e) {
e.printStackTrace();
}
}
// fromFileStr原图片地址,saveToFileStr生成缩略图地址,formatWideth生成图片宽度,formatHeight高度
public void saveImageAsJpg(String fromFileStr, String saveToFileStr,
int formatWideth, int formatHeight) throws Exception {
BufferedImage srcImage;
File saveFile = new File(saveToFileStr);
File fromFile = new File(fromFileStr);
srcImage = javax.imageio.ImageIO.read(fromFile); // construct image
int imageWideth = srcImage.getWidth(null);
int imageHeight = srcImage.getHeight(null);
int changeToWideth = 0;
int changeToHeight = 0;
if (imageWideth > 0 && imageHeight > 0) {
// flag=true;
if (imageWideth / imageHeight >= formatWideth / formatHeight) {
if (imageWideth > formatWideth) {
changeToWideth = formatWideth;
changeToHeight = (imageHeight * formatWideth) / imageWideth;
} else {
changeToWideth = imageWideth;
changeToHeight = imageHeight;
}
} else {
if (imageHeight > formatHeight) {
changeToHeight = formatHeight;
changeToWideth = (imageWideth * formatHeight) / imageHeight;
} else {
changeToWideth = imageWideth;
changeToHeight = imageHeight;
}
}
}
srcImage = imageZoomOut(srcImage, changeToWideth, changeToHeight);
ImageIO.write(srcImage, "JPEG", saveFile);
}
public BufferedImage imageZoomOut(BufferedImage srcBufferImage, int w, int h) {
width = srcBufferImage.getWidth();
height = srcBufferImage.getHeight();
scaleWidth = w;
if (DetermineResultSize(w, h) == 1) {
return srcBufferImage;
}
CalContrib();
BufferedImage pbOut = HorizontalFiltering(srcBufferImage, w);
BufferedImage pbFinalOut = VerticalFiltering(pbOut, h);
return pbFinalOut;
}
private int DetermineResultSize(int w, int h) {
double scaleH, scaleV;
scaleH = (double) w / (double) width;
scaleV = (double) h / (double) height;
// 需要判断一下scaleH,scaleV,不做放大操作
if (scaleH >= 1.0 && scaleV >= 1.0) {
return 1;
}
return 0;
} // end of DetermineResultSize()
private double Lanczos(int i, int inWidth, int outWidth, double Support) {
double x;
x = (double) i * (double) outWidth / (double) inWidth;
return Math.sin(x * PI) / (x * PI) * Math.sin(x * PI / Support)
/ (x * PI / Support);
}
private void CalContrib() {
nHalfDots = (int) ((double) width * support / (double) scaleWidth);
nDots = nHalfDots * 2 + 1;
try {
contrib = new double[nDots];
normContrib = new double[nDots];
tmpContrib = new double[nDots];
} catch (Exception e) {
System.out.println("init contrib,normContrib,tmpContrib" + e);
}
int center = nHalfDots;
contrib[center] = 1.0;
double weight = 0.0;
int i = 0;
for (i = 1; i <= center; i++) {
contrib[center + i] = Lanczos(i, width, scaleWidth, support);
weight += contrib[center + i];
}
for (i = center - 1; i >= 0; i--) {
contrib[i] = contrib[center * 2 - i];
}
weight = weight * 2 + 1.0;
for (i = 0; i <= center; i++) {
normContrib[i] = contrib[i] / weight;
}
for (i = center + 1; i < nDots; i++) {
normContrib[i] = normContrib[center * 2 - i];
}
} // end of CalContrib()
// 处理边缘
private void CalTempContrib(int start, int stop) {
double weight = 0;
int i = 0;
for (i = start; i <= stop; i++) {
weight += contrib[i];
}
for (i = start; i <= stop; i++) {
tmpContrib[i] = contrib[i] / weight;
}
} // end of CalTempContrib()
private int GetRedValue(int rgbValue) {
int temp = rgbValue & 0x00ff0000;
return temp >> 16;
}
private int GetGreenValue(int rgbValue) {
int temp = rgbValue & 0x0000ff00;
return temp >> 8;
}
private int GetBlueValue(int rgbValue) {
return rgbValue & 0x000000ff;
}
private int ComRGB(int redValue, int greenValue, int blueValue) {
return (redValue << 16) + (greenValue << 8) + blueValue;
}
// 行水平滤波
private int HorizontalFilter(BufferedImage bufImg, int startX, int stopX,
int start, int stop, int y, double[] pContrib) {
double valueRed = 0.0;
double valueGreen = 0.0;
double valueBlue = 0.0;
int valueRGB = 0;
int i, j;
for (i = startX, j = start; i <= stopX; i++, j++) {
valueRGB = bufImg.getRGB(i, y);
valueRed += GetRedValue(valueRGB) * pContrib[j];
valueGreen += GetGreenValue(valueRGB) * pContrib[j];
valueBlue += GetBlueValue(valueRGB) * pContrib[j];
}
valueRGB = ComRGB(Clip((int) valueRed), Clip((int) valueGreen),
Clip((int) valueBlue));
return valueRGB;
} // end of HorizontalFilter()
// 图片水平滤波
private BufferedImage HorizontalFiltering(BufferedImage bufImage, int iOutW) {
int dwInW = bufImage.getWidth();
int dwInH = bufImage.getHeight();
int value = 0;
BufferedImage pbOut = new BufferedImage(iOutW, dwInH,
BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < iOutW; x++) {
int startX;
int start;
int X = (int) (((double) x) * ((double) dwInW) / ((double) iOutW) + 0.5);
int y = 0;
startX = X - nHalfDots;
if (startX < 0) {
startX = 0;
start = nHalfDots - X;
} else {
start = 0;
}
int stop;
int stopX = X + nHalfDots;
if (stopX > (dwInW - 1)) {
stopX = dwInW - 1;
stop = nHalfDots + (dwInW - 1 - X);
} else {
stop = nHalfDots * 2;
}
if (start > 0 || stop < nDots - 1) {
CalTempContrib(start, stop);
for (y = 0; y < dwInH; y++) {
value = HorizontalFilter(bufImage, startX, stopX, start,
stop, y, tmpContrib);
pbOut.setRGB(x, y, value);
}
} else {
for (y = 0; y < dwInH; y++) {
value = HorizontalFilter(bufImage, startX, stopX, start,
stop, y, normContrib);
pbOut.setRGB(x, y, value);
}
}
}
return pbOut;
} // end of HorizontalFiltering()
private int VerticalFilter(BufferedImage pbInImage, int startY, int stopY,
int start, int stop, int x, double[] pContrib) {
double valueRed = 0.0;
double valueGreen = 0.0;
double valueBlue = 0.0;
int valueRGB = 0;
int i, j;
for (i = startY, j = start; i <= stopY; i++, j++) {
valueRGB = pbInImage.getRGB(x, i);
valueRed += GetRedValue(valueRGB) * pContrib[j];
valueGreen += GetGreenValue(valueRGB) * pContrib[j];
valueBlue += GetBlueValue(valueRGB) * pContrib[j];
// System.out.println(valueRed+"->"+Clip((int)valueRed)+"<-");
//
// System.out.println(valueGreen+"->"+Clip((int)valueGreen)+"<-");
// System.out.println(valueBlue+"->"+Clip((int)valueBlue)+"<-"+"-->");
}
valueRGB = ComRGB(Clip((int) valueRed), Clip((int) valueGreen),
Clip((int) valueBlue));
// System.out.println(valueRGB);
return valueRGB;
} // end of VerticalFilter()
private BufferedImage VerticalFiltering(BufferedImage pbImage, int iOutH) {
int iW = pbImage.getWidth();
int iH = pbImage.getHeight();
int value = 0;
BufferedImage pbOut = new BufferedImage(iW, iOutH,
BufferedImage.TYPE_INT_RGB);
for (int y = 0; y < iOutH; y++) {
int startY;
int start;
int Y = (int) (((double) y) * ((double) iH) / ((double) iOutH) + 0.5);
startY = Y - nHalfDots;
if (startY < 0) {
startY = 0;
start = nHalfDots - Y;
} else {
start = 0;
}
int stop;
int stopY = Y + nHalfDots;
if (stopY > (int) (iH - 1)) {
stopY = iH - 1;
stop = nHalfDots + (iH - 1 - Y);
} else {
stop = nHalfDots * 2;
}
if (start > 0 || stop < nDots - 1) {
CalTempContrib(start, stop);
for (int x = 0; x < iW; x++) {
value = VerticalFilter(pbImage, startY, stopY, start, stop,
x, tmpContrib);
pbOut.setRGB(x, y, value);
}
} else {
for (int x = 0; x < iW; x++) {
value = VerticalFilter(pbImage, startY, stopY, start, stop,
x, normContrib);
pbOut.setRGB(x, y, value);
}
}
}
return pbOut;
} // end of VerticalFiltering()
int Clip(int x) {
if (x < 0)
return 0;
if (x > 255)
return 255;
return x;
}
}
FROM:http://blog.sina.com.cn/s/blog_5b142cae0100cnmz.html
发表评论
-
java实现斐波那契数列
2017-04-13 15:16 1196public class FibTest { pub ... -
java 堆栈的区别
2015-07-13 21:32 835Java把内存分成两种, ... -
使用StringBuffer的好处是什么?在什么时候使用?
2015-07-13 21:27 806字符串内容较长的时候,特别是这个字符串是动态拼接的时候,用 ... -
ActiveMQ的queue以及topic两种消息处理机制
2015-04-14 10:57 5697JMS:Java Message Server JMS消 ... -
Date数据精度问题
2015-03-30 17:04 1343Java数据精度比Oracle精度大,在java端设置Date ... -
springmvc定时任务配置
2015-02-10 11:19 9581.xml配置头中添加 http://www.spring ... -
计算当日剩余时间
2015-02-09 14:06 1039//计算当日剩余时间 private long getCurr ... -
org.springframework.util.StringUtils的应用
2014-07-18 13:40 1419FROM:http://www.myexception.c ... -
CopyOnWriteArrayList理解与理解[转]
2014-05-29 17:18 857FROM:http://www.cnblogs.com/al ... -
sha1withRSA md5withRSA分析
2014-05-16 11:25 6755source:http://m.blog.csdn.net ... -
java的concurrent用法详解
2014-02-24 14:32 982我们都知道,在JDK1.5之前,Java中要进行业务并发时, ... -
Java获取电脑CPU个数及系统信息
2014-02-20 17:49 17604FROM:http://bingoffice.blog.16 ... -
线程池ExecutorService
2014-02-19 17:57 1229声明:本人所有摘抄作者原文只是为方便学习,收藏所用。 为防 ... -
Sola java搜索引擎服务器
2014-01-26 15:56 2329Sola http://www.open-searc ... -
单例模式
2014-01-07 15:50 567/** * 懒汉式 * @author lihongy ... -
Collections.frequency用法实例
2014-01-07 15:31 8050Collections.frequency(Collecti ... -
java Collections工具类用法
2014-01-07 14:54 1038原文:http://www.cnblogs.com/nayi ... -
经典的java中return和finally问题![转]
2013-11-14 15:45 968原文:http://blog.sina.com.cn/s/ ... -
HashMap、LinkedHashMap、TreeMap 差别[转]
2013-10-31 15:24 981HashMap、LinkedHashMap、TreeMap ... -
java compareTo Comparator
2013-07-24 15:25 646compareTo 只是比较2个字符串,不能进行排序Str ...
相关推荐
Java压缩图片util,可等比例宽高不失真压缩,也可直接指定压缩后的宽高,只能用炫酷来形容,感兴趣就下载看看吧
### JAVA缩小图片尺寸 在Java开发中,对图像进行处理是一项常见的需求,特别是在涉及大量图像数据的应用场景下。本文将详细介绍如何使用Java内置库`javax.imageio`与`java.awt`中的类来实现图片尺寸的缩放功能。...
这个场景中提到的“java压缩图片”可能涉及到使用Java的图像处理库,如Java Advanced Imaging (JAI)或者使用Java标准库中的`java.awt.image.BufferedImage`类。以下是对这个主题的详细阐述: 首先,我们需要理解...
网上找的缩略图生成方法都不够清晰,于是决定自己研究和改进生成缩略图...此方法压缩后的图片小,清晰度高,压缩速度快。5000张图片大概抽根烟的功夫就压缩完了。高清的哦。各种参数都是可配的,方便移植到自己项目中。
java 开发压缩图片文件大小,2m-->200k 不是压缩宽高的
java压缩图片工具类
以上就是Java中压缩图片的几种常见方法,可以根据项目需求和性能考虑选择合适的方式。在实际应用中,除了调整尺寸,还可以通过设置JPEG的压缩质量来进一步减小文件大小。例如,`ImageIO.write()`方法的第三个参数...
在Java编程语言中,处理图片压缩是一项常见的任务,特别是在存储、传输或展示大量图像资源时。本主题将深入探讨如何使用Java实现图片压缩,并能够将其调整到任意大小,同时保持图片质量并避免变形。 首先,我们需要...
根据提供的文件信息,我们可以总结出以下关于“Java压缩上传图片”的相关知识点: ### 1. 知识点一:图片压缩的基本概念 - **定义**:图片压缩是一种减少图像文件大小的技术,通常用于减少存储空间需求或加快网络...
在Java编程语言中,压缩高清图片通常涉及到两个主要的领域:图像处理和文件编码。本文将详细介绍两种常用的方法,它们分别是使用Java自带的ImageIO类和利用第三方库如Apache Commons Compress。 首先,我们来看看...
Java 压缩图片资源的算法demo,采用基本的java流操作实现!
在Java中,压缩图片通常是为了减小文件大小,便于存储或传输,而同时尽可能保持图片质量。上述代码提供了一个名为`CompressPicTools`的类,专门用于压缩图片,保持图片原有的宽高比,同时控制压缩后的失真程度。下面...
<br>在jdk1.6以下的版本环境下,压缩部分图片会很慢,经过我测试,如果图片的DPI越高,速度越慢,一般WEB使用图片DPI都是72,速度很快。大家可以试下。我测试了几张DPI为300,印刷品质的图片,大概要35秒左右,...
* 压缩图片,将图片压缩后以二进制的形式输出 * * @param file * 将要压缩的图片 * @param width * 压缩宽(长度短的做宽) * @param height * 压缩长(长度长的做长) * @return byte[]二进制流 */
这个项目的核心是通过Java实现图片的压缩和缩放功能,结合批量处理能力,能够有效地服务于各种Java Web应用中的图片管理需求。开发者可以根据实际场景,灵活调整处理策略,实现高效、稳定、安全的图片服务。
通过java实现对图片按照尺寸、像素质量实现对图片的压缩处理,并可以对图片制定宽高或者等比压缩
* 压缩图片文件 * 先保存原文件,再压缩、上传 * @param oldFile 要进行压缩的文件全路径 * @param width 宽度 * @param height 高度 * @param quality 质量 * @param smallIcon 小图片的后缀 * @return ...
java中根据设置的宽高等比例压缩图片文件 先保存原文件,再压缩、上传
在Java编程中,图片的上传和按需缩放显示是一项常见的功能,特别是在Web应用或桌面应用中...提供的文档"图片上传显示(缩小图片).doc"应该包含了更详细的代码示例和具体实现细节,建议查阅该文档以获取更完整的信息。