捕获的帧在服务器中向右旋转90度

时间:2018-03-26 07:07:22

标签: java android image-rotation jcodec

从Android手机发送的视频中捕获帧或图像 Jcodec(<artifactId>jcodec</artifactId><artifactId>jcodec-javase</artifactId> Version 0.2.2)用于捕获java中的图像。一切都很好,但显示照片时倾斜到90度。我无法在捕捉帧或显示帧时发现旋转正在发生!

在本地服务器(tomcat7)工作正常(图像在potrait本身)但是当我将代码推送到AWS时它出现了这个问题,它有tomcat8。 AND下载后,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);
    }

1 个答案:

答案 0 :(得分: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;
}