java获取图片宽高(java 获取图片格式)

华为云服务器特价优惠火热进行中!

2核2G2兆仅需 38 元;4核4G3兆仅需 79 元。购买时间越长越优惠!更多配置及优惠价格请咨询客服。

合作流程:
1、点击链接注册/关联华为云账号:点击跳转
2、添加客服微信号:cloud7591,确定产品方案、价格方案、服务支持方案等;
3、客服协助购买,并拉微信技术服务群,享受一对一免费技术支持服务;
技术专家在金蝶、华为、腾讯原厂有多年工作经验,并已从事云计算服务8年,可对域名、备案、网站搭建、系统部署、AI人工智能、云资源规划等上云常见问题提供更专业靠谱的服务,对相应产品提供更优惠的报价和方案,欢迎咨询。

今天给各位分享java获取图片宽高的知识,其中也会对java 获取图片格式进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

微信号:cloud7591
如需了解更多,欢迎添加客服微信咨询。
复制微信号

本文目录一览:

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 如何取得图片的宽度,厘米而非象素

 建议使用PS软件进行调整。

操作步骤:

1.打开需要处理的照片,在“图像”中找到“图像大小”。

2.然后就可以进行对宽和高进行调整了。

注意:要把下方“约束比例”的勾去掉,不然是修改不了想要的数值。

java如何获取数据库里的图片高宽

先把图片取出来,然后看下面,最好在存数据库的时候就把宽高保存下来

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import javax.imageio.ImageIO;

public class CalPit {

    public static void main(String[] args) throws FileNotFoundException, IOException {

        File picture = new File("C:/Users/Administrator/Pictures/我的图片/neusoft.png");

        BufferedImage sourceImg =ImageIO.read(new FileInputStream(picture)); 

        System.out.println(String.format("%.1f",picture.length()/1024.0));

        System.out.println(sourceImg.getWidth());

        System.out.println(sourceImg.getHeight());

    }

}

处理流能够读取picture.jpg文件。java

java在进行jpg图片处理时,比如读取本地或者网络图片的长宽、大小等信息,如果jpg图片受损,那么会抛出异常,这时可以先转换成cmyk模式后再进行。

try {

// 图片处理

picture = new File("图片url");

sourceImg = ImageIO.read(new FileInputStream(picture));

icon.setIconHeight(sourceImg == null ? 0 : sourceImg.getHeight());//获取图片长度

icon.setIconWidth(sourceImg == null ? 0 : sourceImg.getWidth());//获取图片宽度

} catch (Exception e) {

logger.error("图片损坏", e);

try {

//尝试将jpg转换成CMYK

this.exeCommand(picture.getPath());

Image image = null;

image = Toolkit.getDefaultToolkit().getImage(picture.getPath());

MediaTracker mediaTracker = new MediaTracker(new Container());

mediaTracker.addImage(image, 0);

mediaTracker.waitForID(0);

icon.setIconHeight(image.getWidth(null) == -1 ? 0 : image.getWidth(null));

icon.setIconWidth(image.getHeight(null) == -1 ? 0 : image.getHeight(null));

image.getWidth(null);

image.getHeight(null);

} catch (Exception e) {

logger.error("转换图片异常" + e);

}

}

//将jpg转换成CMYK

private boolean exeCommand(String path) {

InputStreamReader ir = null;

LineNumberReader input = null;

try {

Runtime.getRuntime().exec("CLS");

Process process = Runtime.getRuntime().exec("mogrify -colorspace RGB -quality 80 file1".replace("file1", path));

ir = new InputStreamReader(process.getInputStream());

input = new LineNumberReader(ir);

ir.close();

input.close();

} catch (IOException e) {

logger.error("有损JPG图片格式转换为cmyk模式时发生异常", e);

return false;

}

return true;

}

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

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

Java 根据url获取图片高和宽

String imageUrl="";

BufferedImage image=getBufferedImage(imageUrl);

if (image!=null)

{

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

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

}

else

{

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

}

java获取图片宽高的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java 获取图片格式、java获取图片宽高的信息别忘了在本站进行查找喔。

发布于 2023-04-08 13:04:35
收藏
分享
海报
25
目录

    忘记密码?

    图形验证码

    复制成功
    微信号: cloud7591
    如需了解更多,欢迎添加客服微信咨询。
    我知道了