Jpegimagestomovie(录像机)中的图像位置错误

Images positions are wrong in the Jpegimagestomovie (Video Recorder)

我在尝试录制屏幕时遇到问题。

这是开始的代码:

当我按下将记录的按钮时,这是代码:

如果(记录){ System.out.println("RECORDING!");

                            new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    try {
                                        Thread.sleep(1);
                                    } catch (InterruptedException e2) {
                                        // TODO Auto-generated catch block
                                        e2.printStackTrace();
                                    }
                                    while (record) {
                                        count++;
                                        try {
                                            BufferedImage image = new Robot()
                                                    .createScreenCapture(new Rectangle((int) width, (int) height));

                                            File f = new File(
                                                    "LOCATION" + count + ".jpg");
                                            ImageIO.write(image, "JPEG", f);

                                        } catch (AWTException e1) {
                                            e1.printStackTrace();
                                        } catch (IOException e) {
                                            // TODO Auto-generated catch block
                                            e.printStackTrace();
                                        }
                                    }
                                }

                            }).start();

                        }

当我停止录制时,我开始制作视频 (.avi),它是以下代码:

record = false;

                                    System.out.println("RECORDING HAS STOPPED!");
                                    try {
                                        Thread.sleep(3500);
                                    } catch (InterruptedException e1) {
                                        // TODO Auto-generated catch block
                                        e1.printStackTrace();
                                    }
                                    JpegImagesToMovie imageToMovie = new JpegImagesToMovie();

                                    Vector<String> imgList = new Vector<String>();

                                    File f2 = new File("LOCATION");
                                    File[] fileList = f2.listFiles();

                                    for (int i = 0; i < fileList.length; i++) {
                                        imgList.add(fileList[i].getAbsolutePath());

                                    MediaLocator ml;

                                    if ((ml = imageToMovie.createMediaLocator("a.avi")) == null) {
                                        System.exit(0);
                                    }

                                    imageToMovie.doIt((int) width, (int) height, 1, imgList, ml);
                                }

                            }

当它制作视频时,这是我得到的,你可以看到图像完全错位了

Setting the track format to: JPEG
- create DataSink for: file:LOCATION\a.avi
start processing...
  - reading image file: LOCATION\image10.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image100.jpg
    read 115899 bytes.
  - reading image file: LOCATION\image101.jpg
    read 115899 bytes.
  - reading image file: LOCATION\image102.jpg
    read 115899 bytes.
  - reading image file: LOCATION\image11.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image12.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image13.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image14.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image15.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image16.jpg
    read 118065 bytes.
  - reading image file: LOCATION\image17.jpg
    read 118065 bytes.
  - reading image file: LOCATION\image18.jpg
    read 118065 bytes.
  - reading image file: LOCATION\image19.jpg
    read 118065 bytes.
  - reading image file: LOCATION\image2.jpg
    read 106079 bytes.
  - reading image file: LOCATION\image20.jpg
    read 118065 bytes.
  - reading image file: LOCATION\image21.jpg
    read 118065 bytes.
  - reading image file: LOCATION\image22.jpg
    read 118065 bytes.
  - reading image file: LOCATION\image23.jpg
    read 118040 bytes.
  - reading image file: LOCATION\image24.jpg
    read 118169 bytes.
  - reading image file: LOCATION\image25.jpg
    read 118150 bytes.
  - reading image file: LOCATION\image26.jpg
    read 118120 bytes.
  - reading image file: LOCATION\image27.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image28.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image29.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image3.jpg
    read 106612 bytes.
  - reading image file: LOCATION\image30.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image31.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image32.jpg
    read 118265 bytes.
  - reading image file: LOCATION\image33.jpg
    read 118263 bytes.
  - reading image file: LOCATION\image34.jpg
    read 118283 bytes.
  - reading image file: LOCATION\image35.jpg
    read 118283 bytes.
  - reading image file: LOCATION\image36.jpg
    read 118283 bytes.
  - reading image file: LOCATION\image37.jpg
    read 118283 bytes.
  - reading image file: LOCATION\image38.jpg
    read 118274 bytes.
  - reading image file: LOCATION\image39.jpg
    read 118270 bytes.
  - reading image file: LOCATION\image4.jpg
    read 106612 bytes.
  - reading image file: LOCATION\image40.jpg
    read 118209 bytes.
  - reading image file: LOCATION\image41.jpg
    read 118280 bytes.
  - reading image file: LOCATION\image42.jpg
    read 118203 bytes.
  - reading image file: LOCATION\image43.jpg
    read 118202 bytes.
  - reading image file: LOCATION\image44.jpg
    read 118165 bytes.
  - reading image file: LOCATION\image45.jpg
    read 118197 bytes.
  - reading image file: LOCATION\image46.jpg
    read 118251 bytes.
  - reading image file: LOCATION\image47.jpg
    read 118270 bytes.
  - reading image file: LOCATION\image48.jpg
    read 118172 bytes.
  - reading image file: LOCATION\image49.jpg
    read 118162 bytes.
  - reading image file: LOCATION\image5.jpg
    read 106612 bytes.
  - reading image file: LOCATION\image50.jpg
    read 118125 bytes.
  - reading image file: LOCATION\image51.jpg
    read 118101 bytes.
  - reading image file: LOCATION\image52.jpg
    read 118092 bytes.
  - reading image file: LOCATION\image53.jpg
    read 118096 bytes.
  - reading image file: LOCATION\image54.jpg
    read 118075 bytes.
  - reading image file: LOCATION\image55.jpg
    read 118060 bytes.
  - reading image file: LOCATION\image56.jpg
    read 118165 bytes.
  - reading image file: LOCATION\image57.jpg
    read 116149 bytes.
  - reading image file: LOCATION\image58.jpg
    read 117707 bytes.
  - reading image file: LOCATION\image59.jpg
    read 123115 bytes.
  - reading image file: LOCATION\image6.jpg
    read 106612 bytes.
  - reading image file: LOCATION\image60.jpg
    read 123115 bytes.
  - reading image file: LOCATION\image61.jpg
    read 123115 bytes.
  - reading image file: LOCATION\image62.jpg
    read 123575 bytes.
  - reading image file: LOCATION\image63.jpg
    read 123637 bytes.
  - reading image file: LOCATION\image64.jpg
    read 123488 bytes.
  - reading image file: LOCATION\image65.jpg
    read 123488 bytes.
  - reading image file: LOCATION\image66.jpg
    read 123637 bytes.
  - reading image file: LOCATION\image67.jpg
    read 123637 bytes.
  - reading image file: LOCATION\image68.jpg
    read 123481 bytes.
  - reading image file: LOCATION\image69.jpg
    read 123524 bytes.
  - reading image file: LOCATION\image7.jpg
    read 106612 bytes.
  - reading image file: LOCATION\image70.jpg
    read 123533 bytes.
  - reading image file: LOCATION\image71.jpg
    read 123115 bytes.
  - reading image file: LOCATION\image72.jpg
    read 124844 bytes.
  - reading image file: LOCATION\image73.jpg
    read 121337 bytes.
  - reading image file: LOCATION\image74.jpg
    read 119950 bytes.
  - reading image file: LOCATION\image75.jpg
    read 119528 bytes.
  - reading image file: LOCATION\image76.jpg
    read 119528 bytes.
  - reading image file: LOCATION\image77.jpg
    read 119528 bytes.
  - reading image file: LOCATION\image78.jpg
    read 119528 bytes.
  - reading image file: LOCATION\image79.jpg
    read 126779 bytes.
  - reading image file: LOCATION\image8.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image80.jpg
    read 126479 bytes.
  - reading image file: LOCATION\image81.jpg
    read 124403 bytes.
  - reading image file: LOCATION\image82.jpg
    read 124797 bytes.
  - reading image file: LOCATION\image83.jpg
    read 125287 bytes.
  - reading image file: LOCATION\image84.jpg
    read 125276 bytes.
  - reading image file: LOCATION\image85.jpg
    read 125450 bytes.
  - reading image file: LOCATION\image86.jpg
    read 125178 bytes.
  - reading image file: LOCATION\image87.jpg
    read 131495 bytes.
  - reading image file: LOCATION\image88.jpg
    read 127806 bytes.
  - reading image file: LOCATION\image89.jpg
    read 114765 bytes.
  - reading image file: LOCATION\image9.jpg
    read 118168 bytes.
  - reading image file: LOCATION\image90.jpg
    read 114801 bytes.
  - reading image file: LOCATION\image91.jpg
    read 115281 bytes.
  - reading image file: LOCATION\image92.jpg
    read 115281 bytes.
  - reading image file: LOCATION\image93.jpg
    read 115281 bytes.
  - reading image file: LOCATION\image94.jpg
    read 117940 bytes.
  - reading image file: LOCATION\image95.jpg
    read 116221 bytes.
  - reading image file: LOCATION\image96.jpg
    read 115899 bytes.
  - reading image file: LOCATION\image97.jpg
    read 115899 bytes.
  - reading image file: LOCATION\image98.jpg
    read 115899 bytes.
  - reading image file: LOCATION\image99.jpg
    read 115899 bytes.
Done reading all images.
...done processing.

我找不到问题所在,甚至找不到从哪里开始的问题。 我该怎么做才能解决这个问题?

提前致谢。

改变这个:

 File f = new File(
                  "LOCATION" + count + ".jpg");
                   ImageIO.write(image, "JPEG", f);

收件人:

 File f = new File(
                  "LOCATION" + String.format("%04d",count) + ".jpg");
                   ImageIO.write(image, "JPEG", f);

这将添加额外的零,因此 LOCATION0009.jpg 位于 LOCATION0010.jpg 之前,这与 LOCATION9.jpg 和 LOCATION10.jpg 不同。因为它们是按字母顺序而不是数字顺序排列的。看起来 4 位数就足够了,但对于较长的电影,您可能需要更多位数。或者,您可以保留相同的文件名,使用自定义比较器对文件列表进行排序,但它需要稍微多一点的代码。