【问题标题】:Captured frame is rotating 90 degree right in the Server捕获的帧在服务器中旋转 90 度
【发布时间】:2018-03-26 07:07:21
【问题描述】:

从安卓手机发送的视频中捕获帧或图像,已使用 Jcodec(<artifactId>jcodec</artifactId> and <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);
    }

【问题讨论】:

    标签: java android image-rotation jcodec


    【解决方案1】:

    在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;
    }
    

    【讨论】:

    • 您好,感谢您的回复。需要后端解决。这不是前端问题。
    • 如果你以这种方式在客户端捕获它,它会容易得多
    猜你喜欢
    • 2021-06-25
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多