首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在java中将.jpeg图像转换为.jif?(Exif至JFIF)

如何在java中将.jpeg图像转换为.jif?(Exif至JFIF)
EN

Stack Overflow用户
提问于 2015-03-13 09:17:28
回答 1查看 2.9K关注 0票数 0

我从客户那里请求以.JIF格式发送图像。我有java应用程序,但是我不应该用google anithing来讨论如何转换成那个图像类型,我甚至很难将google anithing转换成".JIF“格式本身。

编辑:有人能建议如何在java中将Exif图像转换为JFIF吗?以及如何在这个JFIF图像中添加组件?(遗憾的是,试图使用jheader库时出现了非空指针异常,在google上没有更多的选择。)

EN

回答 1

Stack Overflow用户

发布于 2015-03-13 09:26:40

首先,您需要读取该图像,然后您必须将该图像写入您想要的维度和格式。您必须使用ImageIO类和读取图像来写入它们,使用Graphics2D类替换格式名以jif

代码语言:javascript
复制
 File inputFile = new File(inputImagePath);
    BufferedImage inputImage = ImageIO.read(inputFile);

    // creates output image
    BufferedImage outputImage = new BufferedImage(scaledWidth,
            scaledHeight, inputImage.getType());

    // scales the input image to the output image
    Graphics2D g2d = outputImage.createGraphics();
    g2d.drawImage(inputImage, 0, 0, scaledWidth, scaledHeight, null);
    g2d.dispose();

    // extracts extension of output file
    String formatName = outputImagePath.substring(outputImagePath
            .lastIndexOf(".") + 1);

    // writes to output file
    ImageIO.write(outputImage, formatName, new File(outputImagePath));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29028564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档