導航:首頁 > 編程語言 > 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獲取圖片寬高相關的資料

熱點內容
男主被系統控制的小說下載 瀏覽:951
鈦2電影高清完整版 瀏覽:440
linux啟動項目命令 瀏覽:531
乳山迷霧txt全文閱讀全文小說 瀏覽:885
vm同步命令 瀏覽:14
安卓轉移到ios王者榮耀怎麼登 瀏覽:955
工業壓縮機品牌 瀏覽:182
蘋果系統怎麼更改app的圖標 瀏覽:668
泰劇女同電影 瀏覽:435
人造變異女的電影 瀏覽:237
懷舊經典老錄像片 瀏覽:593
和利時功能塊怎麼加密 瀏覽:30
宣萱電影好看 瀏覽:568
韓國純真時代動態圖 瀏覽:100
關於男主有個能操控別人 瀏覽:303
怎麼測試doh加密 瀏覽:210
歐美 小說 圖片 瀏覽:908
西安程序員未來的發展趨勢 瀏覽:173
叫阿能的電影 瀏覽:261
客車購票小程序源碼 瀏覽:645