导航:首页 > 编程语言 > java获取图片宽高

java获取图片宽高

发布时间:2022-09-02 06:33:55

java 中读取图片宽度和高度总是为-1,怎么办

图片的宽度和高度一般来说如果你不设定的话,它显示的是原始大小,一般来说需要自己设定的,如果疑问的话将你的例子写上来一些,看看。
至于读取动画GIF图片,跟普通图片一样,只需要一个"URL"路径就可以了。

Ⅱ java获取图片分辨率

用apache的开源类 上网下载个sanselan-0.97-incubator.jar架包导入项目中
这个架包所提供的类中可以读取图片的dpi

Ⅲ java 如何获取本地图片的宽度and高度

File image=new File("D:/0.jpg");
try {
BufferedImage localImg = ImageIO.read(new FileInputStream(image));
int width=localImg.getWidth();
int height=localImg.getHeight();
System.out.println("width:"+width);
System.out.println("height:"+height);
}catch (Exception e){
e.printStackTrace();
}

Ⅳ java生成pdf,图片怎么导不进去

不知道你用的什么方法来导的,但是如果通过PDF类库jar包来实现的话,应该是没问题的,参考如下java代码中关于如何插入图片到PDF的方法:


import com.spire.pdf.*;

import com.spire.pdf.graphics.*;

public class AddImage {
public static void main(String[] args) {
//创建文档
PdfDocument pdf = new PdfDocument();

//添加一页
PdfPageBase page = pdf.getPages().add();

//加载图片,并获取图片高宽
PdfImage image = PdfImage.fromFile("fj.png");
int width = image.getWidth()/2;
int height = image.getHeight()/2;

//绘制图片到PDF
page.getCanvas().drawImage(image,50,50,width, height);

//保存文档
pdf.saveToFile("result.pdf");
pdf.dispose();
}

}

Ⅳ java读取tif格式图片的宽和高

java低版本的awt是读不了tif,可以试试扩展包jpi

Ⅵ Java 根据url获取图片高和宽

String imageUrl="http://avatar.csdn.net/9/F/2/1_5iasp.jpg";

BufferedImage image=getBufferedImage(imageUrl);

if (image!=null)

{

System.out.println("图片高度:"+image.getHeight());

System.out.println("图片宽度:"+image.getWidth());

}

else

{

System.out.println("图片不存在!");

}

Ⅶ java如何判断图片文件的宽度和高度

你先使用两个变量获取到图片的宽度和高度,再使用if判断这两个变量是不是你要判断的值。

Ⅷ 相册管理 java实现 功能是图片显示与图片放大缩小 急~~

上楼的我只想说你根本不懂java,这么简单的功能都不能实现,还是一门编程语言吗? 一、部分截图: ①打开 ②放大 ③翻转 ④缩小 二、源程序: import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.File;
public class PhotoFrame extends JFrame implements ActionListener{ Canvas photo;
JPanel p;
JButton open,bigger,smaller,rotate,exit;
JScrollPane sp;
JFileChooser fc;
int w = 150;
int h = 150;
Image image;
int rate = 10;//图片放缩率(单位:像素)

public PhotoFrame(){
init();
this.setTitle ("Java图片查看器");
this.setSize (600,500);
this.setLocationRelativeTo (this);//窗口居中
this.setVisible (true);
this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

}
public void init(){
photo = new Photo();
sp = new JScrollPane(photo);
p = new JPanel();
open = new JButton("open");
bigger = new JButton(" + ");
smaller = new JButton(" - ");
rotate = new JButton(" の ");
exit = new JButton("exit");
//设置前景色
open.setForeground (Color.BLUE);
bigger.setForeground (Color.GREEN);
smaller.setForeground (Color.GREEN);
rotate.setForeground (Color.GREEN);
exit.setForeground (Color.RED);
//设置提示文本
open.setToolTipText ("打开文件");
bigger.setToolTipText ("放大");
smaller.setToolTipText ("缩小");
rotate.setToolTipText ("翻转");
exit.setToolTipText ("退出程序");
//设置边框
p.setBorder (BorderFactory.createEtchedBorder ());
p.add (open);
p.add (bigger);
p.add (smaller);
p.add (rotate);
p.add (exit);
add(sp,BorderLayout.CENTER);
add(p,BorderLayout.SOUTH);
open.addActionListener (this);
bigger.addActionListener (this);
smaller.addActionListener (this);
rotate.addActionListener (this);
exit.addActionListener (this);
}
public static void main(String[] args){
new PhotoFrame();
} public void actionPerformed (ActionEvent e){
if(e.getSource ()==open){//打开
fc = new JFileChooser();
int returnval = fc.showOpenDialog(this);
if(returnval == JFileChooser.APPROVE_OPTION){
File f = fc.getSelectedFile ();
String fileName = f.getName ();
String filePath=fc.getSelectedFile().getAbsolutePath();
System.out.println(filePath);
this.setTitle (fileName+"-Java图片查看器");
//通过文件路径获得图片
image = new ImageIcon(filePath).getImage ();
//获取图片的宽和高
w = image.getWidth (this);
h = image.getHeight (this);
}

}else if(e.getSource ()==bigger){//放大
if(w>0) w+= rate;
else w-= rate;
if(h>0)h+= rate;
else h-= rate;

}else if(e.getSource ()==smaller){//缩小
if(w>0) w-= rate;
else w+= rate;
if(h>0) h-= rate;
else h+= rate;

}else if(e.getSource ()==rotate){//翻转
if(w>0&&h>0){
h*=-1;
}else if(w>0&&h<0){
w*=-1;
}else if(w<0&&h<0){
h*=-1;
}else if(w<0&&h>0){
w*=-1;
}
}else{//退出
System.exit(0);
}
photo.repaint ();//重新绘制
}

class Photo extends Canvas{

public void paint(Graphics g){

int width = this.getWidth();
int height = this.getHeight();
//设置图片左上角坐标
int x = (width-w)/2;
int y = (height-h)/2;
//绘制图片
g.drawImage(image, x, y, w, h,this);

}
}
}
三、补充:1、滚动面板功能没有具体实现2、放大缩小率应该按照图片宽高比来设置,最好用一个滚动条来放大缩小3、翻转功能需要改进 楼主自己试着完善下...

Ⅸ java后台怎样规定上传的图片的大小格式,

用 BufferedImage sourceImg = javax.imageio.ImageIO.read(in);可得到宽高 sourceImg.getWidth()
sourceImg.getHeight()
File file=new File(path);
ImageIO.write(sourceImg, 后缀, file);
file.length();
将图片的文件转为File类型,有length方法可得到文件大小,格式就看文件名的后缀了

Ⅹ java 如何取得图片的宽度,厘米而非象素

建议使用PS软件进行调整。
操作步骤:
1.打开需要处理的照片,在“图像”中找到“图像大小”。

2.然后就可以进行对宽和高进行调整了。
注意:要把下方“约束比例”的勾去掉,不然是修改不了想要的数值。

阅读全文

与java获取图片宽高相关的资料

热点内容
winftplinux 浏览:335
推特app界面如何设置成中文 浏览:452
太空工程师转子编程属性 浏览:32
windowscmd关机命令 浏览:342
云桌面只要服务器装一套软件 浏览:247
电脑右键按到什么导致文件夹全屏 浏览:454
我的世界如何制造服务器主城 浏览:365
linuxssh连不上 浏览:297
永宏plc用什么编程电缆 浏览:371
win激活命令行 浏览:886
新手学电脑编程语言 浏览:893
云空间在哪个文件夹 浏览:926
编程游戏小猫抓小鱼 浏览:790
安卓dosbox怎么打开 浏览:774
服务器无影响是怎么回事 浏览:958
比德电子采购平台加密 浏览:203
加密货币400亿 浏览:524
植发2次加密 浏览:44
vc6查看编译的错误 浏览:596
心理大全pdf 浏览:1002