图片生成java代码 java编程代码图片
高分求java代码,用来生成图片文件!!
//defaultSuffix是jpg
创新互联主要从事成都网站建设、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务永兴,十余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575
public static final boolean resizeImage(String fileName, String suffix) throws Exception {
boolean uploaded = false;
BufferedImage input;
if(suffix.equalsIgnoreCase("tif")||suffix.equalsIgnoreCase("tiff")||suffix.equalsIgnoreCase("png")) {
RenderedImage image = JAI.create("fileload", TurbineServlet.getRealPath(imageRoot + fileName+"."+suffix));
WritableRaster raster = image.copyData(null);
BufferedImage bi = new BufferedImage( image.getColorModel(), raster, true, null);
BufferedImage bi2 = new BufferedImage( maxResizeDimension, bi.getHeight()*maxResizeDimension/bi.getWidth(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bi2.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.setBackground(java.awt.Color.WHITE);//把tiff和png转换后的背景设置为白色
g2.fillRect(0, 0, maxResizeDimension, bi.getHeight()*maxResizeDimension/bi.getWidth());
g2.drawImage(bi, 0, 0, maxResizeDimension, bi.getHeight()*maxResizeDimension/bi.getWidth(), null);
PlanarImage pi = PlanarImage.wrapRenderedImage(bi2);
JAI.create("FileStore", pi, TurbineServlet.getRealPath(resizeRoot + fileName+"."+defaultSuffix).replaceAll("\\\\","\\\\\\\\"), "JPEG", new JPEGEncodeParam());
input = pi.getAsBufferedImage();
int w = maxThumbDimension, h = maxThumbDimension;
BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = output.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(input,0,0,w,h, null);
ImageIO.write(output, defaultSuffix, new File(TurbineServlet.getRealPath(thumbRoot + fileName+"."+defaultSuffix)));
}
else {
input = ImageIO.read(new File(TurbineServlet.getRealPath(imageRoot + fileName+"."+suffix)));
int w = maxThumbDimension, h = maxThumbDimension;
BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = output.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(input,0,0,w,h, null);
ImageIO.write(output, defaultSuffix, new File(TurbineServlet.getRealPath(thumbRoot + fileName+"."+defaultSuffix)));
BufferedImage output2 = new BufferedImage(maxResizeDimension, input.getHeight()*maxResizeDimension/input.getWidth(), BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g2 = output2.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(input,0,0,maxResizeDimension, input.getHeight()*maxResizeDimension/input.getWidth(), null);
ImageIO.write(output2, defaultSuffix, new File(TurbineServlet.getRealPath(resizeRoot + fileName+"."+defaultSuffix)));
}
uploaded = true;
return uploaded;
}
跪求图片生成器java全代码,要求可以画图和获取屏幕并且能保存。拜托各位大神了
正好写了一个,给你看看哈
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Date;
import javax.imageio.ImageIO;
public class ScreenCapturer {
public static void main(String[] args) throws Exception{
Date date = new Date();
Robot rbt = new Robot();
BufferedImage bf = rbt.createScreenCapture(new Rectangle(1440,900)); //这是屏幕分辨率 可以根据自己的屏幕修改
File file = new File("d://"+ date.toString().replace(" ","").replace(":","")+".jpg"); //这是保存路径D盘根目录
ImageIO.write(bf,"jpg",file);
System.out.println("截图成功!保存于D盘根目录下!时间:" + date.toString());
}
}
解析下这个生成图片的Java代码
1.调用"images"文件夹里的文件放在ImageIcon里显示2.在windows下面显示正常Java在图形处理时调用了本地的图形处理库。在利用Java作图形处理(比如:图片缩放,图片签名,生成报表)时,如果运行在windows上不会出问题。如果将程序移植到Linux/Unix上的时候有可能出现图形不能显示的错误。3.提示信息:"Can'tconnecttoX11windowserver"这是由于Linux的图形处理需要一个XServer服务器。(关于Linux的图形处理模式参考Tomcat的修改如下:打开%Tomcat_home%/bin/catalina.sh文件在文件的86%处,启动Tomcat的脚本中加上:-Djava.awt.headless=true/参考:"$_RUNJAVA"$JAVA_OPTS$CATALINA_OPTS/-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS"-classpath"$CLASSPATH"/-Dcatalina.base="$CATALINA_BASE"/-Dcatalina.home="$CATALINA_HOME"/-Djava.io.tmpdir="$CATALINA_TMPDIR"/-Djava.awt.headless=true/org.apache.catalina.startup.Bootstrap"$@"start/"$CATALINA_BASE"/logs/catalina.out21if[!-z"$CATALINA_PID"];thenecho$!$CATALINA_PIDfifielif["$1"="stop"];then保存后,重新启动就可以处理图形了。
有没有通过UML图自动生成Java代码的工具
常用的是StarUML,其他一些UML软件,如Rational Rose都是可以的,即可正向生成,也可以逆向生成
从文件中读取图片和写入图片到文件里的java代码是什么?
首先导入各种需要的包:
import java.awt.Image;
import javax.imageio.ImageIO;
import java.io.*;
读取图片的方法如下:
Image[] array = new Image[10];
Image image = ImageIO.read(new File("d:\\source.gif"));//根据你实际情况改文件路径吧
array[0] = image;
图片读出来了。
如果你有一个Image对象,想把它写入文件可以这样做:
BufferedImage image = ImageIO.read(new File("d:\\source.gif"));
//要想保存这个对象的话你要把image声明为BufferedImage 类型
ImageIO.write(image, "png", new File("f:\\test.png"));
名称栏目:图片生成java代码 java编程代码图片
文章转载:http://azwzsj.com/article/hghjps.html