📄 createimage.java
字号:
package control;
import java.io.IOException;
import javax.servlet.http.*;
import javax.servlet.*;
import javax.imageio.*;
import java.io.*;
import java.awt.image.*;
import java.awt.*;
import model.*;
import java.util.*;
public class CreateImage
{
public String getImage(int Width ,int Height,OutputStream os )
{
if(Width <= 0)
Width = 60;
if(Height <= 0)
Height = 22;
BufferedImage image = new BufferedImage(Width,Height,BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.white);
g.fillRect(0,0,Width,Height);
g.setColor(Color.black);
g.drawRect(0,0,Width-1,Height-1);
//String rand = "fdsf";
String rand = String.valueOf((int)(Math.random()*10000));
//System.out.println(rand);
switch(rand.length())
{
case 1: rand = "000"+rand;
break;
case 2: rand = "00"+rand;
break;
case 3: rand = "0"+rand;
break;
}
//System.out.println(rand);
g.setColor(Color.black);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.drawString(rand,10,15);
Random random=new Random();
for(int iIndex=0;iIndex<88;iIndex++)
{
int x=random.nextInt(Width);
int y=random.nextInt(Height);
g.drawLine(x,y,x,y);
}
g.dispose();
try
{
ImageIO.write(image,"JPEG",os);
}
catch(IOException e){return "";}
return rand;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -