简体   繁体   English

更改Java中的网络摄像头尺寸

[英]Change the Webcam Dimensions in Java

I need to resize my Webcam frame size in order to add a text box at the bottom. 我需要调整网络摄像头框架的大小,以便在底部添加一个文本框。 However, whenever I change the Dimensions, I get the following error: 但是,每当更改尺寸时,都会出现以下错误:

java.lang.IllegalArgumentException: Incorrect dimension [1280x600] possible ones are [176x144] [320x240] [640x480] [1280x720] 

Here is my code right now: 现在是我的代码:

else {
    Dimension[] nonStandardResolutions = new Dimension[] {
        WebcamResolution.HD720.getSize() // Add HD resolution
};


webcam.setCustomViewSizes(nonStandardResolutions);
//webcam.setViewSize(WebcamResolution.HD720.getSize());
webcam.setViewSize(new Dimension(1280, 600));
webcam.open(); // this call will throw a WebcamException if it is in use, taken care of below
webcamPanel = new WebcamPanel(webcam);
add(webcamPanel);
cameraInUse = false;
cameraNotDetected = false;
return; // Return as soon as the first available camera is found

How can I change the Dimensions without getting the error? 如何更改尺寸而不出现错误?

This is just a guess because I have not worked with a webcam using Java before. 这只是一个猜测,因为我以前从未使用过使用Java的网络摄像头。

Below is an example, but here is a sample code you can try to implement. 下面是一个示例,但是这里是您可以尝试实现的示例代码。

    Dimension[] nonStandardResolutions = new Dimension[] { 
        WebcamResolution.PAL.getSize(), 
        WebcamResolution.HD720.getSize(), 
        new Dimension(2000, 1000), 
        new Dimension(1000, 500), 
    }; 

    // your camera have to support HD720p to run this code 
    Webcam webcam = Webcam.getDefault(); 
    webcam.setCustomViewSizes(nonStandardResolutions); 
    webcam.setViewSize(WebcamResolution.HD720.getSize()); 

Although it seems like the only difference between this and your code seems to be the WebcamResolution.HD720.getSize(). 尽管这似乎与您的代码之间的唯一区别似乎是WebcamResolution.HD720.getSize()。 Try adding more dimensions to your nonstandard dimension. 尝试将更多尺寸添加到非标准尺寸。

https://github.com/sarxos/webcam-capture/blob/master/webcam-capture/src/example/java/CustomResolutionExample.java https://github.com/sarxos/webcam-capture/blob/master/webcam-capture/src/example/java/CustomResolutionExample.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM