1

从android手机发送的视频中捕获帧或图像,使用Jcodec(<artifactId>jcodec</artifactId><artifactId>jcodec-javase</artifactId> Version 0.2.2)在java中捕获图像。一切正常,但在显示照片时向右倾斜 90 度。我无法发现在捕获框架或显示框架时正在发生旋转!

在本地服务器(tomcat7)中工作正常(图像在 potrait 本身中)但是当我将代码推送到 AWS 时出现了这个问题,它有 tomcat8。并且下载后,来自 AWS 的图像(JPEG)大小为 28kb,来自本地服务器的大小为 118kb。

我在这里分享我的代码任何人请告诉我哪里出了问题,解决这个问题的任何链接都会非常有用。

帧捕获代码:

int frameNumber = 1;
Picture picture = FrameGrab.getFrameFromFile(file, frameNumber);
BufferedImage bufferedImage = AWTUtil.toBufferedImage(picture);
ImageIO.write(bufferedImage, "jpg", new File(id + File.separator + fileName + "_" + fileName + ".jpg"));

图片显示代码:

public ResponseEntity<Resource> getPhoto(@PathVariable(value = "id") Integer id) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.IMAGE_JPEG);
        String absolutePath = new File(".").getAbsolutePath();
        File file = new File(Paths.get(absolutePath).getParent() + "/" + id);
        if (null != file) {
            FilenameFilter beginswithm = new FilenameFilter() {
             public boolean accept(File directory, String filename) {
                return filename.startsWith("photo");
             }
           };
            File[] files = file.listFiles(beginswithm);
            if (null != files && files.length > 0) {
              Resource resource = null;
              for (final File f : files) {
              headers.set("Content-Disposition", "inline; filename=" + f.getName());
              resource = appContext.getResource("file:"
                              + Paths.get(absolutePath).getParent() + "/" + id + "/" + f.getName());                     
               return new ResponseEntity<>(resource, headers, HttpStatus.OK);
             }
          }
       }
        RecruiterResponseBean resBean = new RecruiterResponseBean();
        resBean.setStatusMessage(Constants.FAILED);
        resBean.setStatusCode(Constants.FAILED_CODE);
        return new ResponseEntity(resBean, HttpStatus.NOT_FOUND);
    }
4

1 回答 1

0

在 android 中,您可以使用 ExifInterface 来确定图像/视频是否有旋转。

ExifInterface exifInterface = new ExifInterface(mFile.getPath());
int orientation = exifInterface.getAttributeInt(TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
Matrix matrix = new Matrix();
switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        matrix.postRotate(90);
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        matrix.postRotate(180);
        break;
    case ExifInterface.ORIENTATION_ROTATE_270:
        matrix.postRotate(270);
        break;
    default:
        break;
}
于 2018-03-26T10:22:27.877 回答