导航:首页 > 编程语言 > java图像读取

java图像读取

发布时间:2022-08-07 05:45:00

㈠ 如何用java读取屏幕图象

大概思路就是下面这样了width=|x1-x2|,high=|y1-y2|
class ScreenCapture
{
/**
* @param args
*/
private Robot robot = null;
private Rectangle scrRect = null;
int x1,y1;
int width,high;

public ScreenCapture()
{
try
{
robot = new Robot();
}
catch (Exception ex)
{
System.out.println(ex.toString());
}
scrRect = new Rectangle(x1, y1, width, height);
}

public BufferedImage captureScreen()
{
BufferedImage bufImg = null;

try
{
bufImg = robot.createScreenCapture(scrRect);

}
catch (Exception e)
{
System.out.println(e.toString());
}
return bufImg;
}
}

㈡ 给定一幅图像,用java读取每个像素的RGB三个颜色值

int rgbR;
int rgbG;
int rgbB;
int minx = 0;
int miny = 0;
try {
File file = new File("E:\\dd.png");
BufferedImage image = ImageIO.read(file);
int width = image.getWidth();//图片宽度
int height = image.getHeight();//图片高度

for (int i = minx; i < width; i++) {
for (int j = miny; j < height; j++) {
int pixel = image.getRGB(i, j); // 下面三行代码将一个数字转换为RGB数字
rgbR = (pixel & 0xff0000) >> 16;
rgbG = (pixel & 0xff00) >> 8;
rgbB = (pixel & 0xff);
System.out.println("i=" + i + ",j=" + j + ":(" + rgbR + "," + rgbG + "," + rgbB + ")");
}
}

System.out.println("图片宽度为:"+width+",高度为:"+height);

} catch (IOException e) {
System.out.println("读取文件出错");
e.printStackTrace();
}

㈢ 请教如何用Java语言读取jpg图片,并显示

1、获取文件夹的路径 2、得到文件夹中的有图片的名称,可以存到数组或者集合中 3、你再到jsp页面做显示, 4、下面是获取路径和文件名的代码,前台显示的代码自己写 String path = 文件夹路径; String names = ""; try { File f = new File(path)

㈣ java 图片文件的读取和写入问题

while(i != -1){
os.write(b, 0, b.length);
i=is.read(b, 0, b.length);
}
关键是这里,b仅仅是作为一个缓冲区,是可以反复使用的。
建议不要设置的太小至少1024是比较好的。

㈤ java 怎么一次性读取多张图片

实现思路:一次性读取选中的统一路径下的多张图片,实现整体复制。
//复制文件夹
package com.cdd.util;
import java.io.*;
public class FileUtil {
private static void (File[] files, File d) {
if (!d.exists()) //如果指定目录不存在
d.mkdir(); //创建目录
for (int i = 0; i < files.length; i++) { //循环遍历要复制的文件夹
if (files[i].isFile()) { //如果文件夹中是文件
try {
FileInputStream fis = new FileInputStream(files[i]); //创建FileInputStream对象
FileOutputStream out = new FileOutputStream(new File(d
.getPath()
+ File.separator + files[i].getName())); //复制后文件的保存路径
int count = fis.available();
byte[] data = new byte[count];
while ((str = bre.readLine())!= null) //读取文件通过readline方法可以有效的避免乱码
out.write(str ); //将读取的信息写入文件中
}
out.close(); //关闭流
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (files[i].isDirectory()) { //如果文件夹中是一个路径
File des = new File(d.getPath() + File.separator
+ files[i].getName()); //在复制后路径中创建子文件夹
des.mkdir();
(files[i].listFiles(), des); //再次调用本方法
}
}
System.out.println("文件夹复制成功");
}

㈥ 怎么用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读取TIFF图像方法

Asprise offers TIFF writer and reader library as valued add-on to our flagship procts – Asprise OCR & JTwain. Tagged Image File Format (abbreviated TIFF) is a file format for mainly storing raster images. With Asprise Java TIFF library, you can easily create, manipulate (read and write), disassemble TIFF files easily.

你可以去他们家的网站去download这个API,然后就可以比较简单的搞定这个TIFF的读入问题了。

㈧ java如何读取文件夹中的图片并在界面显示

下面给你提供一个实现,该实现采用了代理模式。这个实现包含两个文件,分别是Client.java和ImageIcoProxy.java,ImageIcoProxy.java负责了图片的延迟加载,你可以修改为不延迟即可。

Client.java的代码为:
import java.awt.Graphics;
import java.awt.Insets;

import javax.swing.Icon;
import javax.swing.JFrame;

public class Client extends JFrame {
private static int IMG_WIDTH = 510;
private static int IMG_HEIGHT = 317;
private Icon imgProxy = null;
public static void main(String[] args) {
Client app = new Client();
app.setVisible(true);
}

public Client() {
super("Virture Proxy Client");
imgProxy = new ImageIcoProxy("D:/test.jpg", IMG_WIDTH, IMG_HEIGHT);
this.setBounds(100, 100, IMG_WIDTH + 10, IMG_HEIGHT + 30);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g) {
super.paint(g);
Insets insets = getInsets();
imgProxy.paintIcon(this, g, insets.left, insets.top);
}
}

ImageIcoProxy.java的代码为:
import java.awt.Component;
import java.awt.Graphics;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;

public class ImageIcoProxy implements Icon {

private ImageIcon realIcon = null;
private String imgName;
private int width;
private int height;
boolean isIconCreated = false;
public ImageIcoProxy(String imgName, int width, int height) {
this.imgName = imgName;
this.width = width;
this.height = height;
}

public int getIconHeight() {
return realIcon.getIconHeight();
}

public int getIconWidth() {
return realIcon.getIconWidth();
}

public void paintIcon(final Component c, Graphics g, int x, int y) {
if (isIconCreated) {
//已经加载了图片,直接显示
realIcon.paintIcon(c, g, x, y);
g.drawString("Just Test", x + 20, y + 370);
} else {
g.drawRect(x, y, width-1, height-1);
g.drawString("Loading photo...", x+20, y+20);
synchronized(this) {
SwingUtilities.invokeLater(new Runnable() {

public void run() {
try {
Thread.currentThread().sleep(2000);
realIcon = new ImageIcon(imgName);
isIconCreated = true;
} catch (Exception e) {
e.printStackTrace();
}
c.repaint();
}

}
);
}
}
}

}

㈨ java中读取图片文件的函数

new File("/place.jpg") 请调试是否正确创建了代表文件的实例

阅读全文

与java图像读取相关的资料

热点内容
好兴动app还款怎么登录不上去了 浏览:663
郑州云服务器托管 浏览:720
服务器地址跟踪 浏览:978
免费google云服务器 浏览:516
摘译和编译的英文 浏览:359
热泵压缩机选型 浏览:121
op手机微信加密如何解除 浏览:386
如何在王牌战争找到高爆率服务器 浏览:13
江浙小学语文辅导课用什么APP 浏览:99
新梦幻大陆服务器地址 浏览:241
网吧服务器怎么更换壁纸 浏览:530
linux命令方法 浏览:332
linux下载freetype 浏览:123
程序员入驻平台 浏览:327
程序员大战外挂 浏览:745
html实例教程pdf 浏览:157
linux命令开放所有权限 浏览:575
30岁能学会编程 浏览:737
小火箭的服务器是什么 浏览:967
cad查信息命令 浏览:402