资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java图片锐化代码 java图片缩小代码

java图像处理 - 图片上的数字字母圆滑处理方法

抗锯齿的代码我倒是有一个,你试一下,输出图片第一行是不抗锯齿的,第二行是抗锯齿的。

为金门等地区用户提供了全套网页设计制作服务,及金门网站建设行业解决方案。主营业务为网站设计制作、做网站、金门网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

public static void main(String[] args) throws IOException {

BufferedImage image = new BufferedImage(400, 200, BufferedImage.TYPE_4BYTE_ABGR_PRE);

Graphics2D g2d = image.createGraphics();

g2d.setColor(Color.WHITE);

g2d.fillRect(0, 0, 400, 200);

g2d.setColor(Color.BLACK);

g2d.setFont(new Font("Arial", Font.PLAIN, 37));

g2d.drawString("jjyygg789@163.com", 10f, 40f);

g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);// 设置抗锯齿效果

g2d.drawString("jjyygg789@163.com", 10f, 80f);

File outputfile = new File("D:\\TestGraphics.png");

ImageIO.write(image, "PNG", outputfile);

}

求一个用BufferedImage这个改变图片大小的JAVA代码!~!

import java.awt.Image;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import javax.imageio.ImageIO;

import com.sun.image.codec.jpeg.JPEGCodec;

import com.sun.image.codec.jpeg.JPEGEncodeParam;

import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class ImageZipUtil {

/**

* 压缩图片文件br

* 先保存原文件,再压缩、上传

*

* @param oldFile

* 要进行压缩的文件全路径

* @param width

* 宽度

* @param height

* 高度

* @param quality

* 质量

* @param smallIcon

* 小图片的后缀

* @return 返回压缩后的文件的全路径

*/

public String zipImageFile(String oldFile, int width, int height,

float quality, String smallIcon) {

if (oldFile == null) {

return null;

}

String newImage = null;

try {

/** 对服务器上的临时文件进行处理 */

Image srcFile = ImageIO.read(new File(oldFile));

int w = srcFile.getWidth(null);

System.out.println(w);

System.out.println(smallIcon);

System.out.println(smallIcon);

int h = srcFile.getHeight(null);

System.out.println(h);

//width = w/4;

//height = h/4;

/** 宽,高设定 */

BufferedImage tag = new BufferedImage(width, height,

BufferedImage.TYPE_INT_RGB);

tag.getGraphics().drawImage(srcFile, 0, 0, width, height, null);

String filePrex = oldFile.substring(0, oldFile.indexOf('.'));

/** 压缩后的文件名 */

newImage = filePrex + smallIcon

+ oldFile.substring(filePrex.length());

/** 压缩之后临时存放位置 */

FileOutputStream out = new FileOutputStream(newImage);

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(tag);

/** 压缩质量 */

jep.setQuality(quality, true);

encoder.encode(tag, jep);

out.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return newImage;

}

/**

* 保存文件到服务器临时路径

*

* @param fileName

* @param is

* @return 文件全路径

*/

public String writeFile(String fileName, InputStream is) {

if (fileName == null || fileName.trim().length() == 0) {

return null;

}

try {

/** 首先保存到临时文件 */

FileOutputStream fos = new FileOutputStream(fileName);

byte[] readBytes = new byte[512];// 缓冲大小

int readed = 0;

while ((readed = is.read(readBytes)) 0) {

fos.write(readBytes, 0, readed);

}

fos.close();

is.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return fileName;

}

public static void main(String[] args){

ImageZipUtil u = new ImageZipUtil();

u.zipImageFile("e:/SAM_0006.JPG", 128, 128, 1f, "x2");

}

}

我java系统里面要加一个图片编辑的功能 应该用什么技术做

Java 完全可以出色的实现多媒体的编辑与处理,包括图象的处理技术( JGraph )、动画技术( JFlash )、声音视频技术( JMF )等等;

Java 对图象处理进行了很好的支持,通过 java 提供的类,我们完全可以对图象进行各种常见的操作和变换;

1、 java图形图象处理所用到的相关类与接口:

java.awt.color、java.awt.grahpics、java.awt.image、

java.awt.image.bufferedimage、java.awt.image.LookupOp、

java.awt.image.ConvolveOp、java.awt.image.AffineTransformOp、

bufferedimageop接口及其实现类等;

2、 java 图形图象处理可以完成的功能:

图象文件的打开(浏览)与保存(支持 jpg 、 jpeg 、 gif 、 png 等)、放大镜操作、旋转与镜像操作、反色和其他反色、黑白色阈值处理、亮度调整、缩放显示、边缘化、图形的锐化和钝化、其它功能等; .


名称栏目:java图片锐化代码 java图片缩小代码
本文网址:http://cdkjz.cn/article/docosdj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220