当前位置:首页 » 编程语言 » java图片

java图片

发布时间: 2022-01-15 19:02:03

java添加图片

JAVA是非常灵活的语言,你自己稍动一下手指就能编个控件的。
class ImageBox extends JLabel ...

⑵ JAVA 图片

double[] myList=new List()[0];
double max=myList[0];
myList未定义

⑶ JAVA图片输出

等着拿分.......
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
* @author alanwei
*
*/
public class Test {

public static BufferedImage createImage(int width, int height, String s) {
Font font = new Font("Serif", Font.BOLD, 10);
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D)bi.getGraphics();
g2.setBackground(Color.WHITE);
g2.clearRect(0, 0, width, height);
g2.setPaint(Color.RED);

FontRenderContext context = g2.getFontRenderContext();
Rectangle2D bounds = font.getStringBounds(s, context);
double x = (width - bounds.getWidth()) / 2;
double y = (height - bounds.getHeight()) / 2;
double ascent = -bounds.getY();
double baseY = y + ascent;

g2.drawString(s, (int)x, (int)baseY);

return bi;
}

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedImage image = createImage(100, 20, "123456789");

File file = new File("image.jpg");
if (!file.exists()) {
file.createNewFile();
}

if (image != null) {
ImageIO.write(image, "jpg", file);
}
}
}

⑷ JAVA 画图片

如果image是在同一个包下的话,可以直接在路劲上写你的image的名字。比如包名叫com..chaojunjie 那么下面有个Test.java,在里面再加一张图片test.image,那么久直接Toolkit.getDeafaultToolkit.getImage('test.image')就可以了。当然这样写不是做好的。最好单独和src同目录下建个包叫images然后把拓片单独放里面。
然后获得相对路径Toolkit.getDeafaultToolkit.getImage(this.getClass.getFile('里面写你的包名+图片名'))

⑸ java 加载图片的几种方式

第一种方法:

Image bg; //或者是BufferedImage bg;

Pool2(){

try{

String file="图片的路径";

bg =ImageIO.read(new File(file));

}catch(Exception e){

e.printStackTrace();

}

}

第二种方法:这种方法用BufferedReader就不行

Image background;

Pool2(){

try{

String file="文件的路径";

background=Toolkit.getDefaultToolkit().getImage(file);

}catch(Exception e){

e.printStackTrace();

}

}

另外我们有时喜欢把图片放在工程的src目录下这样访问这些图片时就要用下面的方法。以src下的image文件下的01.jpg为例

Image image=null;

image = ImageIO.read(getClass().getResourceAsStream("/image/01.jpg"));

⑹ java加载图片

InputStream in = CommonLoggerFactory.class
.getResourceAsStream("/e/djtu/smartcow/icons/0.jpg");
byte[] kao = new byte[1024*1000];
int size = 0;
int length = 0;
try {
while ((length = in.read(kao, 0, 1024*1000)) != -1) {
size += length;
}
// Close the input stream and return bytes
in.close();

OutputStream output = response.getOutputStream();
output.write(kao, 0, size);
output.close();

} catch (IOException e) {
e.printStackTrace();
}

CommonLoggerFactory日志生成类

⑺ java图片输出

等着拿分.......
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
* @author alanwei
*
*/
public class Test {

public static BufferedImage createImage(int width, int height, String s) {
Font font = new Font("Serif", Font.BOLD, 10);
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D)bi.getGraphics();
g2.setBackground(Color.WHITE);
g2.clearRect(0, 0, width, height);
g2.setPaint(Color.RED);

g2.drawString(s, 0, 5 + height / 2);

return bi;
}

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedImage image = createImage(100, 20, "123456789");

File file = new File("image.jpg");
if (!file.exists()) {
file.createNewFile();
}

if (image != null) {
ImageIO.write(image, "jpg", file);
}
}
}

⑻ JAVA 图片语句

使用jsp小脚本
<%
for(int i=0;i<num;i++){
%>

<img src="" >//在双引号中可以写路径也可以在for之前把图片路径存放在一个数组中,然后在双引号内写<%=数组[下标] %>
<%
}
%>
例如你可以这样写:
<%
String [] parth=new String[];//定义数组,用来存放图片路径,本代码中的图片路径为上一级文件夹的image文件夹中.
for(int i=0;i<parth.length;i++){
%>
<img src="<%=parth[i] %>">
<%} %>
也可把数组内容写为:String [] parth=new String[];
这样的话要在使用时这样写:<img src="../image/<%=parth[i] %>">

两中路径的写法是一样的.以后有什么可以交流的可以给我邮件. 加我好友

⑼ java生成jpg图片 并且实现文字和图片混排

response.setHeader("Cache-Control","no-cache");
String str="";
String sum="";
for(int i=0;i<4;i++){
Random random=new Random();
int j=Math.round(random.nextFloat()*35);
char x=str.charAt(j);
sum+=x+"";
}
request.getSession().setAttribute("Code",sum);
BufferedImage bufferedImage=new BufferedImage(50,20,BufferedImage.TYPE_3BYTE_BGR);
Graphics2D graphics2D=(Graphics2D)bufferedImage.getGraphics();
graphics2D.setColor(Color.blue);
graphics2D.fill3DRect(0,0,50,20,false);
graphics2D.setColor(Color.YELLOW);
graphics2D.drawString(sum,10,12);
response.setContentType("image/jpeg");
ServletOutputStream output;
try {
output = response.getOutputStream();
JPEGImageEncoder encoder= JPEGCodec.createJPEGEncoder(output);
encoder.encode(bufferedImage);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

⑽ 用java怎么读取图片

思路:使用 java.awt.Image包下的Image可以接收图片。读取则使用ImageIO对象。

代码如下:

/**
* 读取图片,首先导入以下的包
*/
import java.awt.Image;
import javax.imageio.ImageIO;
import java.io.*;

/**
* 用Image对象来接收图片
* 路径根据实际情况修改
*/
Image image = ImageIO.read(new File("c:\\1.png"));
System.out.println(image.getSource());

热点内容
为什么ipad需要密码解锁 发布:2024-09-21 04:06:22 浏览:210
mariadb存储过程 发布:2024-09-21 03:56:05 浏览:514
压缩壳脱壳机 发布:2024-09-21 03:14:33 浏览:93
热血街篮为什么是服务器维护中 发布:2024-09-21 03:08:19 浏览:937
喇叭怎么配置功放 发布:2024-09-21 03:06:50 浏览:751
为什么安卓的内存没有苹果的内存 发布:2024-09-21 03:06:50 浏览:231
swift解压 发布:2024-09-21 02:31:47 浏览:704
移动中心怎么配置安卓系统 发布:2024-09-21 02:27:16 浏览:606
安卓手机旧版app怎么下载 发布:2024-09-21 02:12:35 浏览:799
方舟知道ip怎么加入服务器 发布:2024-09-21 02:12:14 浏览:791