把图片用java代码输出 java生成图片
高分求java代码,用来生成图片文件!!
//defaultSuffix是jpg
创新互联是一家专业提供榆阳企业网站建设,专注与成都网站建设、网站设计、html5、小程序制作等业务。10年已为榆阳众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。
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.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Test{
public static void main(String[] args){
try {
File f1 = new File("a.jpg");
BufferedImage image = ImageIO.read(f1);
Graphics g = image.getGraphics();
g.setFont(new Font("Serif",Font.BOLD,20));
g.setColor(Color.red);
g.drawString("happy new year!", 10, 20);
File f2 = new File("copy.jpg");
ImageIO.write(image, "JPEG", f2);
} catch (IOException e) {
e.printStackTrace();
}
}
}
java中输出图片的代码
final ImageView iv=(ImageView)findViewById(R.id.iv);
Button bt=(Button)findViewById(R.id.bt);
bt.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1)
{
// TODO: Implement this method
if(iv.getDrawable()!=null)
iv.setImageResource(R.id.photo);
else iv.setImageResource(0);
}
});
怎样用Java代码打印并输出如下图形
这样可以
public static void main(String[] args) {
String[] temps = {"A","B","C","D","E","F","G"};
for (int i = 1; i = temps.length; i++) {
for(int j = temps.length; j i; j--){
System.out.print(" ");
}
for (int j = 0; j i*2-1; j++) {
System.out.print(temps[i-1]);
}
System.out.println();
}
}
运行结果
A
BBB
CCCCC
DDDDDDD
EEEEEEEEE
FFFFFFFFFFF
GGGGGGGGGGGGG
java怎么在控制台输出一张jpg的图片
输出图片的base64编码
//imgFile是图片的路径
public static void getImageStr(String imgFile) {
InputStream inputStream = null;
byte[] data = null;
try {
inputStream = new FileInputStream(imgFile);
data = new byte[inputStream.available()];
inputStream.read(data);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
} // 加密
BASE64Encoder encoder = new BASE64Encoder();
System.out.println(encoder.encode(data));
}
请问 用java语句输出如图片图案应该怎么做?
1、代码如下:
public class Main
{
public static void main(String[] args) {
System.out.println("Hello World!");
//主循环
for(int i =10;i0;i--){
//输出空格
for(int k=i;k0;k--){System.out.print(" ");}
//输出数字
for(int j=i;j=10;j++){
System.out.print(j+" ");
}System.out.println(" ");
}
}
}
2、效果如图
网站题目:把图片用java代码输出 java生成图片
网站网址:http://ybzwz.com/article/hggscs.html