日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

camera.swf java_java调用摄像头保存图片上传功能

發布時間:2023/12/2 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 camera.swf java_java调用摄像头保存图片上传功能 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在項目中要用到jsp頁面實現網頁采集攝像頭圖像,并實現上傳的功能,頁面主要js調用的,所以可以使用多種語言php,asp等都可以使用,而且是跨瀏覽器的。

可以整合的到SSH項目中和struts1或者struts2項目中

使用方法1:

下載 printscreen4web-jsp.war(最下面有下載地址),然后放到tamcat目錄webapp文件夾下面,啟動tomcat,訪問http://127.0.0.1:8080/printscreen4web-jsp/

主要調用文件 :1.index.html.2avatar.jsp

String imagepath1="";

//編輯頁面中包含 camera.swf 的 HTML 代碼

public String renderHtml(String id,String basePath,String input)

{

String outinput="";

try {

outinput = URLDecoder.decode(input);

}catch(Exception e)

{

System.out.println("解碼錯誤!");

}

String[] tmp_input=outinput.split("@");//input傳遞的類型和uid

//System.out.println(input+","+tmp_input.length);

String uc_api =URLEncoder.encode(basePath+"upload/avatar.jsp");

String urlCameraFlash = "camera.swf?nt=1&inajax=1&appid=1&input="+input+"&uploadSize=1000&ucapi="+uc_api;

urlCameraFlash = "";

return urlCameraFlash;

}

public String getFileExt(String fileName) {

// 下面取到的擴展名錯誤,只有三位,而如html的文件則有四位

// extName = fileName.substring(fileName.length() - 3, fileName.length()); //擴展名

int dotindex = fileName.lastIndexOf(".");

String extName = fileName.substring(dotindex, fileName.length());

extName = extName.toLowerCase(); //置為小寫

return extName;

}

private byte[] getFlashDataDecode(String src)

{

char []s=src.toCharArray();

int len=s.length;

byte[] r = new byte[len / 2];

for (int i = 0; i < len; i = i + 2)

{

int k1 = s[i] - 48;

k1 -= k1 > 9 ? 7 : 0;

int k2 = s[i + 1] - 48;

k2 -= k2 > 9 ? 7 : 0;

r[i / 2] = (byte)(k1 << 4 | k2);

}

return r;

}

public boolean saveFile(String path,byte[]b){

try{

FileOutputStream fs = new FileOutputStream(path);

fs.write(b, 0, b.length);

fs.close();

return false;

}catch(Exception e){

return true;

}

}

%>

String uploadtype= request.getParameter("uploadtype");

//圖片上傳類型:頭像,logo,圖片分別對應參數:head,logo,pic沒有傳遞,默認為PIC

if("".equals(uploadtype))

{

uploadtype="pic";

}

//最終裁剪好的圖片存放位置

String uid=request.getParameter("uid");

imagepath1=uploadtype+"/"+uid+"_big.jpg";

String action= request.getParameter("a");

//String input=request.getParameter("input");

String path = request.getContextPath();

String infoFilePath="";

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

if(action==null){

%>

body{

margin: 0;

border: 0;

}

function updateavatar() {

var img1="";

if(window.opener.document.getElementById("imgpath1"))

{

window.opener.document.getElementById("imgpath1").value=img1;

window.opener.document.getElementById("showimg1").src="upload/"+img1;

}

window.close();

}

out.print(renderHtml("5",basePath,URLEncoder.encode(uploadtype+"@"+uid)));

%>

}else if("uploadavatar".equals(action)){//上傳臨時圖片,可以自己實現

//System.out.println(action);

UploadUtil uploadUtil = new UploadUtil();

boolean isOk = uploadUtil.initParam(pageContext,request);

if (isOk == false)

{

System.out.println("頁面出錯:" + uploadUtil.getMsg());

return;

}

//上傳附件

isOk = uploadUtil.uploadFile("");

if (isOk == false)

{

System.out.println("頁面出錯:" + uploadUtil.getMsg());

return;

}

Map map = uploadUtil.getUploadFiles();

if (map == null)

{

System.out.println("頁面出錯:上傳附件失敗");

}

if (map.size() == 0)

{

System.out.println("頁面出錯:沒有上傳附件");

return;

}

//獲取附件文件名和存儲文件路徑

for (Iterator iter = map.keySet().iterator(); iter.hasNext();)

{

infoFilePath = (String) iter.next();

String infoFileName = (String) map.get(infoFilePath);

//infoFilePath=infoFilePath.substring(infoFilePath.lastIndexOf("\\")+1);

//System.out.println(infoFilePath);

//infoFilePath=infoFilePath.substring(infoFilePath.indexOf("webapps")+8);

infoFilePath=infoFilePath.replaceAll("\\\\", "/");

//System.out.println(basePath+"upload"+infoFilePath);

out.clear();

out.print(basePath+"upload"+infoFilePath);

}

}else if("rectavatar".equals(action)){//縮略圖

String avatar1 = request.getParameter("avatar1");//大

String avatar2 = request.getParameter("avatar2");//中

String avatar3 = request.getParameter("avatar3");//小

String output ="";

try {

output = URLDecoder.decode(request.getParameter("input"));

}catch(Exception e)

{

System.out.println("解碼錯誤!");

}

String[] tmp_input=output.split("@");//input傳遞的類型和uid

String pathff = request.getSession().getServletContext().getRealPath("/")+ "upload\\";

String imgfilepath=pathff+tmp_input[0];

imagepath1=imgfilepath+"/"+tmp_input[1]+"_big.jpg";

out.clear();

boolean a1=saveFile(imagepath1,getFlashDataDecode(avatar1));

if(a1){

out.print("<?xml version=\"1.0\" ?>");

}else{

out.print("<?xml version=\"1.0\" ?>");

}

}

%>

總結

以上是生活随笔為你收集整理的camera.swf java_java调用摄像头保存图片上传功能的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。