2011-04-30 3 views
0

다음은 xiggler를 사용하여 화면을 캡처하고 비디오를 만드는 코드입니다. 제대로 작동하지만 생성 된 비디오에는 마우스 커서가 없습니다. 또한 마우스 포인터를 캡쳐하여 마우스 동작을 표시하려고합니다.xuggler를 사용하여 마우스 포인터가있는 화면 캡처

어떤 사람이 나를 안내 할 수 있습니까?

package com.test.video; 

import java.awt.AWTException; 
import java.awt.Dimension; 
import java.awt.Graphics2D; 
import java.awt.Image; 
import java.awt.MouseInfo; 
import java.awt.Rectangle; 
import java.awt.Robot; 
import java.awt.Toolkit; 
import java.awt.image.BufferedImage; 
import java.io.IOException; 
import java.util.concurrent.TimeUnit; 

import javax.imageio.ImageIO; 


import com.xuggle.mediatool.IMediaWriter; 
import com.xuggle.mediatool.ToolFactory; 
import com.xuggle.xuggler.ICodec; 

public class ScreenRecordingExample { 

    private static final double FRAME_RATE = 5; 

    private static final int SECONDS_TO_RUN_FOR = 120; 

    private static final String outputFilename = "c:/mydesktop.mp4"; 

    private static Dimension screenBounds; 

    private static Graphics2D imageGraphics; 

    public static Image m_MouseIcon = null; 

    public static void main(String[] args) { 

     // let's make a IMediaWriter to write the file. 
     final IMediaWriter writer = ToolFactory.makeWriter(outputFilename); 

     screenBounds = Toolkit.getDefaultToolkit().getScreenSize(); 

     // We tell it we're going to add one video stream, with id 0, 
     // at position 0, and that it will have a fixed frame rate of FRAME_RATE. 
     writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4, screenBounds.width/2, screenBounds.height/2); 

     long startTime = System.nanoTime(); 

     try { 
      m_MouseIcon = ImageIO.read(ScreenRecordingExample.class.getResource("resource/captionMouseIcon.png")); 
     } catch (IOException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 

     for (int index = 0; index < SECONDS_TO_RUN_FOR * FRAME_RATE; index++) { 

      // take the screen shot 
      BufferedImage screen = getDesktopScreenshot(); 

      // convert to the right image type 
      BufferedImage bgrScreen = convertToType(screen, BufferedImage.TYPE_3BYTE_BGR); 

      // encode the image to stream #0 
      writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime, TimeUnit.NANOSECONDS); 

      // sleep for frame rate milliseconds 
      try { 
       Thread.sleep((long) (1000/FRAME_RATE)); 
      } 
      catch (InterruptedException e) { 
       // ignore 
      } 

     } 

     // tell the writer to close and write the trailer if needed 
     writer.close(); 

    } 

    public static BufferedImage convertToType(BufferedImage sourceImage, int targetType) { 

     BufferedImage image; 

     // if the source image is already the target type, return the source image 
     if (sourceImage.getType() == targetType) { 
      image = sourceImage; 
     } 
     // otherwise create a new image of the target type and draw the new image 
     else { 
      image = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), targetType); 
      image.getGraphics().drawImage(sourceImage, 0, 0, null); 
     } 

     return image; 

    } 

    private static BufferedImage getDesktopScreenshot() { 
     try { 
      Robot robot = new Robot(); 
      Rectangle captureSize = new Rectangle(screenBounds); 
      return robot.createScreenCapture(captureSize); 
     } 
     catch (AWTException e) { 
      e.printStackTrace(); 
      return null; 
     } 

    } 

} 

감사합니다,

+0

다음은 예제 코드입니다. http://stackoverflow.com/questions/2962271/how-to-capture-screen-image-with-mouse-pointer-on-it-in-java/2962377#2962377 –

답변

0

사용 MouseInfo.getPointerInfo().getLocation() 포인터의 현재 위치를 얻을 수있다. '가까운 팩시밀리'()의 포인터를 BufferedImage에 그립니다 (1).


1) Screenshooter의 경우, 포인터의 GIF 이미지를 사용합니다.

+1

복용 중에는 동적 커서 유형이 제공되지 않습니다. 스크린 샷 –

0

Java Native Access (JNA)를 사용하여 OS 특정 마우스 커서 유형을 실시간으로 검색 한 다음 시스템 파일 (Windows의 경우 user32.dll)에서 이미지를 추출하고 스크린 샷에 오버레이 할 수 있습니다.

+0

어디에서이 문제를 해결할 수 있습니까? 솔루션에 대한 자세한 내용을 알려 주실 수 있습니까? –