Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用xuggler使用鼠标指针捕获屏幕_Java_Xuggle - Fatal编程技术网

Java 使用xuggler使用鼠标指针捕获屏幕

Java 使用xuggler使用鼠标指针捕获屏幕,java,xuggle,Java,Xuggle,下面是使用Xugler捕获屏幕并制作视频的代码,它工作正常,但生成的视频中没有鼠标光标。我还想捕获鼠标指针以显示鼠标活动 有人能在这方面指导我吗 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.R

下面是使用Xugler捕获屏幕并制作视频的代码,它工作正常,但生成的视频中没有鼠标光标。我还想捕获鼠标指针以显示鼠标活动

有人能在这方面指导我吗

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

    }

}
谢谢,

使用MouseInfo.getPointerInfo.getLocation获取指针的当前位置。在BuffereImage上的该点处绘制指针的“关闭传真”


1对于,我使用指针的GIF图像。

您可以使用Java Native AccessJNA实时检索操作系统特定的鼠标光标类型,然后从windows中的system fileuser32.dll提取其图像并覆盖在屏幕截图上

下面是示例代码。这不会在截图时提供动态光标类型。您可以在哪里解决此问题?你能给我们更多关于解决方案的细节吗?