这是第一个程序文件:
import javaawt;
import javaxswing;
public class ImagePanel extends JPanel {
private Image img;
public ImagePanel(Image img) {
thisimg = img;
Dimension size = new Dimension(imggetWidth(null),
imggetHeight(null));
setSize(size);
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setLayout(null);
}
public void paintComponent(Graphics g) {
gdrawImage(img,0,0,null);
}
}
这是第二个:
import javaawt;
import javaxswing;
public class ImageTest {
public static void main(String[] args) {
ImagePanel panel = new ImagePanel(new
ImageIcon("images/01jpg")getImage());
JFrame frame = new JFrame("多问自己,会使你少犯错误!");
framegetContentPane()add(panel);
framepack();
framesetVisible(true);
}
}
try{
File _file = new File("C:/Documents and Settings/mayuanfei/My Documents/女友照片jpg"); //读入文件
Image src = javaximageioImageIOread(_file); //构造Image对象
int wideth=srcgetWidth(null); //得到源图宽
int height=srcgetHeight(null); //得到源图长
Systemoutprintln(wideth+","+height);
}catch(Exception e){
eprintStackTrace();
}
private static final String imgDir="C:/Program Files/Tencent/TM2009/Users/273367058/FileRecv";//这里填上目录全名就行了
static{
try{
File dir = new File(imgDir);
File[] imgFiles = dirlistFiles(new FilenameFilter(){
public boolean accept(File dir, String name) {
return nametoLowerCase()endsWith("jpg");
}
});
String imageUrl=">
大概思路就是下面这样了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)
{
Systemoutprintln(extoString());
}
scrRect = new Rectangle(x1, y1, width, height);
}
public BufferedImage captureScreen()
{
BufferedImage bufImg = null;
try
{
bufImg = robotcreateScreenCapture(scrRect);
}
catch (Exception e)
{
Systemoutprintln(etoString());
}
return bufImg;
}
}
上传 后台获取的时候直接从数据库拿路径
下面这是servlet的内容:
package demo;
import javaioFile;
import javaioIOException;
import javaioPrintWriter;
import javautilList;
import javaxservletServletException;
import javaxservlet>
以上就是关于JAVA中怎样获取文件夹里的图片 并把图片在Panel里显示出来全部的内容,包括:JAVA中怎样获取文件夹里的图片 并把图片在Panel里显示出来、java 如何获取图片的像素值、java 访问url获取图片等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)