Ⅰ 如何使用java啟用電腦的攝像頭攝相拍照
方法/步驟
1
第一種方法,官方軟體打開。
第一步,檢測攝像頭驅動是否正常安裝。
右擊計算機,點擊管理進入計算機的管理界面,選擇設備管理器,查看裡面的攝像頭驅動是否已經安裝並正常運行。
2
第二步,下載安裝官方軟體。
我們的電腦一般都會安裝好相應的驅動了,只不過還沒有相應的軟體的支持,如果你的電腦是正版系統的話,那麼這些都會帶著,如果不是我們需要自己到官網去下載安裝。以聯想為例(YouCam)。
3
第三步,點擊軟體即可打開筆記本自帶的攝像頭。
安裝完成後後自動生成一個快捷方式,雙擊快捷方式即可打開攝像頭。
4
第二種方法,360魔法攝像頭打開。
如果你的電腦安有360安全衛士的話,那麼就很方便了。打開360安全衛士,進入功能大全界面添加360魔法攝像頭功能即可。
5
點擊安裝後你可以直接點擊打開電腦的攝像頭,也可以在計算機中打開,因為這是你的計算機(我的電腦)中會多出一個攝像頭的功能。
Ⅱ JAVA代碼如何調用客戶端攝像頭
首先到sun下載最新的jmf,然後安裝。
然後,說一下需求
1. 用攝像頭拍照
2. 在文本框輸入文件名
3. 按下拍照按鈕,獲取攝像頭內的圖像
4. 在拍下的照片上有一紅框截取固定大小的照片。
5. 保存為本地圖像為jpg格式,不得壓縮畫質
技術關鍵,相信也是大家最感興趣的部分也就是如何讓一個攝像頭工作,並拍下一張照片了。
利用jmf,代碼很簡單:
//利用這三個類分別獲取攝像頭驅動,和獲取攝像頭內的圖像流,獲取到的圖像流是一個swing的component組件類
public static player player = null;
private capturedeviceinfo di = null;
private medialocator ml = null;
//文檔中提供的驅動寫法,為何這么寫我也不知:)
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);
}
}
catch (exception e)
{
e.printstacktrace();
}
接下來就是點擊拍照,獲取攝像頭內的當前圖像。
代碼也是很簡單:
private jbutton capture;
private buffer buf = null;
private buffertoimage btoi = null;
private imagepanel imgpanel = null;
private image img = null;
private imagepanel imgpanel = null;
jcomponent c = (jcomponent) e.getsource();
if (c == capture)//如果按下的是拍照按鈕
{
framegrabbingcontrol fgc =(framegrabbingcontrol) player.getcontrol( "javax.media.control.framegrabbingcontrol ");
buf = fgc.grabframe(); // 獲取當前禎並存入buffer類
btoi = new buffertoimage((videoformat) buf.getformat());
img = btoi.createimage(buf); // show the image
imgpanel.setimage(img);
}
保存圖像的就不多說了,以下為示例代碼
bufferedimage bi = (bufferedimage) createimage(imgwidth, imgheight);
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(1f, false);//不壓縮圖像
encoder.setjpegencodeparam(param);
try
{
encoder.encode(bi);
out.close();
}
catch (java.io.ioexception io)
{
system.out.println( "ioexception ");
}
把.jar文件導入。下載了jmf後需要安裝,安裝後你的那個jmf目錄下就會有一個lib文件夾裡面有.jar文件,然後打開eclipse,右鍵選擇你的工程-〉屬性-〉java build path-> library-〉add external jars 找到你的jmf目錄下lib的那個文件夾然後選中那些文件導入就ok了。
然後利用工具提供的導入文件幫助,一個一個導就OK了
Ⅲ 如何使用java調用攝像頭
正好我最近在弄JAVA攝像頭東西
JAVA載入攝像頭需要用JMF框架,這個LZ可以去SUN的主頁下到,具體的配置搜下就有了
我這個是在用JFrame的
載入的代碼是這樣的:
public JPanel contentPane = new JPanel();
public void getvideo(){
CaptureDeviceInfo di = null;
MediaLocator ml = null;
Player player = null;
Vector deviceList = CaptureDeviceManager.getDeviceList(null);
if(deviceList!=null)
{
for(int i=0;i<deviceList.size();i++)
{
di=(CaptureDeviceInfo)deviceList.elementAt(i);
if(di.getName().startsWith("vfw:")){
ml=di.getLocator();
}
}
}
else{
System.err.print("No Capture Device");
System.exit(-1);
}
try {
player = Manager.createRealizedPlayer(ml);
player.start();
Component comp;
if((comp = player.getVisualComponent())!=null)
{ comp.setBounds(new Rectangle(0, 40,320, 240));
contentPane.add(comp,BorderLayout.NORTH);
}
} catch (NoPlayerException e) {
e.printStackTrace();
} catch (CannotRealizeException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
再把contentPane添加到JFrame裡面,這個就可以在一個JFrame的框架用攝像頭了
還有,要注意個事,就是第一次使用攝像頭的話,要用JMF帶的程序JMF Registry選到capture Devices中注冊下,不然是找不到驅動的
Ⅳ java遠程訪問攝像頭怎麼實現
OpenOffice java api:
簡單的說就是利用java程序可以操作OpenOffice的所有功能,比如創建doc文檔,插入文字,設置文字格式等等。
1. OpenOffice 給程序員提供了一個叫UNO (UniversalNetwork Objects)的組件技術.我理解的UNO: OpenOffice 類似於web程序中的伺服器,程序員寫的代碼類似於客戶端,利用UNO提供的介面和服務去完成對OpenOffice文檔的操作。所以寫程序首先要搭建 UNO環境:
1. 下載 OpenOffice
2.復制UNO提供的jar包: unoil.jar, java_uno.jar, juh.jar, jurt.jar, ridl.jar, unoloader.jar. (ps: 安裝了SDK之後在文件夾找)到自己的工程中,引入它們。
3. 下載文檔:DevelopersGuide.pdf.
4. 安裝了SDK後,重新啟動一下機器,然後就可以按照 DevelopersGuide 來學習 UNO 編程了。
5. 需要ava 環境。
補充: 安裝了SDK後, java, c++幫助文檔,樣常式序,其他關於sdk的信息 都放在本地openOffice安裝路徑一個叫sdk目錄下面,enjoy it !
總結一下已經實現的功能和碰到的問題匯總:
1. 首先要得到遠程office組件的上下文.通過:
com.sun.star.uno.XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
得到,如果OpenOffice安裝路徑不是在工程的路徑下面(我自己猜的), 就會報:
com.sun.star.comp.helper.BootstrapException: no office executable found!
解決辦法: 黑其源代碼, 看了源代碼就會發現其實OpenOffice是在尋找本地的soffice的shell文件,所以弄個變數來保存soffice在系統中的路徑,重新寫一 個Bootstrap就可以了。詳細請參照:論壇 。
2. 得到 XMultiComponentFactory (ComponentFactory 工廠)
com.sun.star.lang.XMultiComponentFactory xMCF = xContext.getServiceManager();
3. 得到各種組件可以通過下面代碼:
// docType 是 與 soffice 同目錄下面的OpenOffice的其他shell文件,swrite等等
protected XComponent newDocComponent(String docType)
throws java.lang.Exception {
String loadUrl = "private:factory/" + docType;
mxRemoteServiceManager = this.getRemoteServiceManager();
Object desktop = mxRemoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", mxRemoteContext);
XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime
.queryInterface(XComponentLoader.class, desktop);
PropertyValue[] loadProps = new PropertyValue[0];
return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", 0,
loadProps);
}
4.得到 XTextDocument
XComponent xEmptyWriterComponent = newDocComponent("swriter");
XTextDocument mxDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,
xEmptyWriterComponent);
5. 得到一個文檔的引用
XText mxDocText = mxDoc.getText();
6. 得到文檔的屬性列表
XPropertySet mxDocProps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, mxDoc);
7. 建立游標,用來插入新的內容。
XTextCursor mxDocCursor = mxDocText.createTextCursor();
XSentenceCursor xSentenceCursor = (XSentenceCursor) UnoRuntime
.queryInterface(XSentenceCursor.class, mxDocCursor);
XWordCursor xWordCursor = (XWordCursor) UnoRuntime.queryInterface(
XWordCursor.class, mxDocCursor);
8.得到游標屬性列表
XPropertySet xCursorProps = (XPropertySet) UnoRuntime .queryInterface(XPropertySet.class, mxDocCursor);
9.設置插入文字格式
xCursorProps.setPropertyValue("CharFontName", "宋體");
xCursorProps.setPropertyValue("CharWeight", new Float(FontWeight.BOLD));
xCursorProps.setPropertyValue("CharHeight", new Float(10.5));
// 居中顯示
xCursorProps.setPropertyValue("ParaAdjust", com.sun.star.style.ParagraphAdjust.CENTER);
10.在該游標處插入信息
mxDocText.insertString(xSentenceCursor, 「Hello World", true);
11. 保存的關鍵代碼
protected void storeDocComponent(XComponent xDoc, String storeUrl)
throws java.lang.Exception {
XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
XStorable.class, xDoc);
PropertyValue[] storeProps = new PropertyValue[1];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = "MS Word 97";
openOfficeJavaLogger.debug("... store \"" + xDoc.toString() + "\" to \"" + storeUrl
+ "\".");
xStorable.storeAsURL(storeUrl, storeProps);
}
Ⅳ java能開發視頻聊天嗎
肯定的說:能!
大致的說一下原理:
首先你要學習一下java的網路編程方面的東西,像TCP/IP UDP協議等等的東西,因為要編寫視頻聊天程序,這些理論性的東西是必須的。
現在假設你已經可以編寫出簡單功能的網路聊天功能的軟體了,想在就是要用你編寫軟體驅動起你的攝像頭了。首先你要確保你的攝像頭的開發商已經給了你該攝像頭的驅動介面,有了這個介面你就可以編寫出可以驅動起該攝像頭的java程序了。
之後你要學習一下JNI,也就是Java Native Interface,學會這個,你就可以用你編寫的java程序來調用攝像頭驅動程序(驅動一般都是用C或C++)編寫,有了JNI,你就可以讓你的java程序和驅動的C或C++程序來進行通訊了。
之後把攝像頭的實時攝像信息傳到網路的另一邊(用到網路編程),就可以讓對方看到你了(前提是對方也安裝了你編寫的軟體,否則你們之間的通訊可能沒人能看懂)。
這是個大致的過程,實現的過程肯定會暈倒這樣那樣的問題,不過不要擔心,學習的過程就是遇到問題,思考問題,解決問題的過程。這樣慢慢的你就發現你已經很牛了!
Ⅵ java如何控制球機攝像頭
用JMF(Java Media Framework)
調用攝像頭驅動,發送拍照命令,保存圖片
Ⅶ 電腦上有多個攝像頭時。怎樣編寫一個java程序調用我指定的那個攝像頭
先下載jfm安裝好,裡面可以裡面可以看到你有哪些攝像頭驅動的,還可以對每個攝像頭進行設置
你要用java進行攝像頭開發必須先下載安裝jmf.
比如:
captureDeviceInfo = CaptureDeviceManager.getDevice("vfw:Microsoft WDM Image Capture (Win32):0"); // 載入驅動
這個載入的驅動名稱就是和jfm中的驅動對應的,如果你有其他攝像頭在jmf中可以看到驅動的,直接載入那個驅動就可以了
Ⅷ java 怎麼調用攝像頭
正好我最近在弄JAVA攝像頭東西
JAVA載入攝像頭需要用JMF框架,這個LZ可以去SUN的主頁下到,具體的配置搜下就有了
我這個是在用JFrame的
載入的代碼是這樣的:
public JPanel contentPane = new JPanel();
public void getvideo(){
CaptureDeviceInfo di = null;
MediaLocator ml = null;
Player player = null;
Vector deviceList = CaptureDeviceManager.getDeviceList(null);
if(deviceList!=null)
{
for(int i=0;i<deviceList.size();i++)
{
di=(CaptureDeviceInfo)deviceList.elementAt(i);
if(di.getName().startsWith("vfw:")){
ml=di.getLocator();
}
}
}
else{
System.err.print("No Capture Device");
System.exit(-1);
}
try {
player = Manager.createRealizedPlayer(ml);
player.start();
Component comp;
if((comp = player.getVisualComponent())!=null)
{ comp.setBounds(new Rectangle(0, 40,320, 240));
contentPane.add(comp,BorderLayout.NORTH);
}
} catch (NoPlayerException e) {
e.printStackTrace();
} catch (CannotRealizeException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
再把contentPane添加到JFrame裡面,這個就可以在一個JFrame的框架用攝像頭了
還有,要注意個事,就是第一次使用攝像頭的話,要用JMF帶的程序JMF Registry選到capture Devices中注冊下,不然是找不到驅動的
Ⅸ JAVA裡面有什麼方法調用攝像頭拍照的
利用jmf,代碼很簡單:
//利用這三個類分別獲取攝像頭驅動,和獲取攝像頭內的圖像流,獲取到的圖像流是一個swing的component組件類
public static player player = null;
private capturedeviceinfo di = null;
private medialocator ml = null;
//文檔中提供的驅動寫法,為何這么寫我也不知:)
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);
}
}
catch (exception e)
{
e.printstacktrace();
}
接下來就是點擊拍照,獲取攝像頭內的當前圖像。
代碼也是很簡單:
private jbutton capture;
private buffer buf = null;
private buffertoimage btoi = null;
private imagepanel imgpanel = null;
private image img = null;
private imagepanel imgpanel = null;
jcomponent c = (jcomponent) e.getsource();
if (c == capture)//如果按下的是拍照按鈕
{
framegrabbingcontrol fgc =(framegrabbingcontrol) player.getcontrol("javax.media.control.framegrabbingcontrol");
buf = fgc.grabframe(); // 獲取當前禎並存入buffer類
btoi = new buffertoimage((videoformat) buf.getformat());
img = btoi.createimage(buf); // show the image
imgpanel.setimage(img);
}
保存圖像的就不多說了,以下為示例代碼
bufferedimage bi = (bufferedimage) createimage(imgwidth, imgheight);
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(1f, false);//不壓縮圖像
encoder.setjpegencodeparam(param);
try
{
encoder.encode(bi);
out.close();
}
catch (java.io.ioexception io)
{
system.out.println("ioexception");
}
Ⅹ Java連接攝像頭項目細節怎麼寫
Java連接攝像頭項目細節怎麼寫建議找專業寫代碼的人。
Java是一門面向對象的編程語言,不僅吸收了C++語言的各種優點,還摒棄了C++里難以理解的多繼承、指針等概念,因此Java語言具有功能強大和簡單易用兩個特徵。Java語言作為靜態面向對象編程語言的代表,極好地實現了面向對象理論,允許程序員以優雅的思維方式進行復雜的編程。