gpt4 book ai didi

用于通过网络摄像头捕获图像的java代码UnsatisfiedLinkError

转载 作者:搜寻专家 更新时间:2023-10-30 23:00:54 25 4
gpt4 key购买 nike

我使用的是 windows7 64 位操作系统。源代码用于通过网络摄像头捕获图像:

import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import javax.media.*;
import javax.media.format.*;
import javax.media.util.*;
import javax.media.control.*;
import javax.media.protocol.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import com.sun.image.codec.jpeg.*;

public class SwingCapture extends Panel implements ActionListener
{
public static Player player = null;
public CaptureDeviceInfo di = null;
public MediaLocator ml = null;
public JButton capture = null;
public Buffer buf = null;
public Image img = null;
public VideoFormat vf = null;
public BufferToImage btoi = null;
public ImagePanel imgpanel = null;

public SwingCapture()
{
setLayout(new BorderLayout());
setSize(320,550);

imgpanel = new ImagePanel();
capture = new JButton("Capture");
capture.addActionListener(this);

String str1 = "vfw:Logitech USB Video Camera:0";
String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
di = CaptureDeviceManager.getDevice(str2);
ml = di.getLocator();

try
{
player = Manager.createRealizedPlayer(ml);
player.start();
Component comp;

if ((comp = player.getVisualComponent()) != null)
{
add(comp,BorderLayout.NORTH);
}
add(capture,BorderLayout.CENTER);
add(imgpanel,BorderLayout.SOUTH);
}
catch (Exception e)
{
e.printStackTrace();
}
}



public static void main(String[] args)
{
Frame f = new Frame("SwingCapture");
SwingCapture cf = new SwingCapture();

f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
playerclose();
System.exit(0);}});

f.add("Center",cf);
f.pack();
f.setSize(new Dimension(320,550));
f.setVisible(true);
}


public static void playerclose()
{
player.close();
player.deallocate();
}


public void actionPerformed(ActionEvent e)
{
JComponent c = (JComponent) e.getSource();

if (c == capture)
{
// Grab a frame
FrameGrabbingControl fgc = (FrameGrabbingControl)
player.getControl("javax.media.control.FrameGrabbingControl");
buf = fgc.grabFrame();

// Convert it to an image
btoi = new BufferToImage((VideoFormat)buf.getFormat());
img = btoi.createImage(buf);

// show the image
imgpanel.setImage(img);

// save image
saveJPG(img,"c:\\test.jpg");
}
}

class ImagePanel extends Panel
{
public Image myimg = null;

public ImagePanel()
{
setLayout(null);
setSize(320,240);
}

public void setImage(Image img)
{
this.myimg = img;
repaint();
}

public void paint(Graphics g)
{
if (myimg != null)
{
g.drawImage(myimg, 0, 0, this);
}
}
}


public static void saveJPG(Image img, String s)
{
BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(img, null, null);

FileOutputStream out = null;
try
{
out = new FileOutputStream(s);
}
catch (java.io.FileNotFoundException io)
{
System.out.println("File Not Found");
}

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(0.5f,false);
encoder.setJPEGEncodeParam(param);

try
{
encoder.encode(bi);
out.close();
}
catch (java.io.IOException io)
{
System.out.println("IOException");
}
}

}

这段代码编译成功。运行代码时,出现以下运行时错误:

Exception in thread "VFW Request Thread" java.lang.UnsatisfiedLinkError:JMFSecurityManager: java.lang.UnsatisfiedLinkError:no jmvfw in 
java.library.path at com.sun.media.JMFSecurityManager.loadLibrary(JMFSecurityManager.java:206)
at com.sun.media.protocol.vfw.VFWCapture.<clinit><VFWCapture.java:19>
at com.sun.media.protocol.vfw.VFWSourceStream.doConnect(VFWSourceStream.java:241)
at com.sun.media.protocol.vfw.VFWSourceStream.run(VFWSourceStream.java:763)
at java.cdlang.Thread.run(Thread.java:619)

请把这个问题的解决方案发给我/

最佳答案

这是一个解决方案,但我还没有尝试过:https://forums.oracle.com/forums/thread.jspa?messageID=10191973

基本上,它说的是卸载 64 位 jdk 并安装 32 位。

关于用于通过网络摄像头捕获图像的java代码UnsatisfiedLinkError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3701957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com