java image byte base64_java检查图片问题

背景

含有错误信息的图片是检测不到人脸的。

  • 错误的读文件方式,会过滤掉图片的exif信息。
  • 验证:将该错误的base64值传入https://www.hitoy.org/tool/file_base64.php生成图片;并将图片放入http://metapicz.com/#landing中,发现并没有exif信息。

通过工具查看,其实图片的方向是旋转了270度的。

b9f89f20975aca19d9c5488f47e1f289.png

获取的图片的方向是向上的

4059e08505a6577d2d13f87b5a29d704.png

运行结果,读出来的值的确是不太一样。

8ab83e8ab963322cc0e3e4620b5de234.png

直接上干货,都是代码

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Base64;
public class photo {
    public static void main(String [] args) {
        // 错误的读文件方式,会过滤掉图片的exif信息。
        // 验证:将该错误的base64值传入https://www.hitoy.org/tool/file_base64.php生成图片;并将图片放入http://metapicz.com/#landing中,发现并没有exif信息。
        //File input = new File("C:UsersailanzhouPicturesSaved Pictures07181.jpg");
        //File input = new File("C:UsersailanzhouPictures12051.jpg");
        File input = new File("C:Usersp_yingfaluDesktop04Picture04_10_01.jpg");
        try {
            BufferedImage bufferedImage = ImageIO.read(input);
            final ByteArrayOutputStream os = new ByteArrayOutputStream();
            ImageIO.write(bufferedImage,"jpg",os);
            byte[] bytes = os.toByteArray();
            String a = Base64.getEncoder().encodeToString(bytes);
            System.out.println(a);
        }catch ( Exception e ){
            e.printStackTrace(System.err);
        }
        // 正确的读文件方式,不会过滤掉图片的exif信息。生成的base64与https://www.hitoy.org/tool/file_base64.php一致。
        try {
            //InputStream in = new FileInputStream("C:UsersailanzhouPicturesSaved Pictures07181.jpg");
            InputStream in = new FileInputStream("C:Usersp_yingfaluDesktop04Picture04_10_01.jpg");
            byte[] data = new byte[in.available()];
            in.read(data);
            in.close();
            String b = Base64.getEncoder().encodeToString(data);
            System.out.println(b);
        }
        catch ( Exception e ){
            e.printStackTrace(System.err);
        }
    }
//
}

这是简书上实现的 https://www.jianshu.com/p/9513041db67c

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值