Terry.Li-彬

          虛其心,可解天下之問;專其心,可治天下之學(xué);靜其心,可悟天下之理;恒其心,可成天下之業(yè)。

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            143 隨筆 :: 344 文章 :: 130 評(píng)論 :: 0 Trackbacks

          前兩天看了一個(gè)flex攝像頭拍照的程序感覺不錯(cuò)不過是C#

          代碼的,有點(diǎn)遺憾,今天給他改成了java代碼的。

          java 代碼:

          1. public ? void ?processRequest(HttpServletRequest?request,??
          2. ????????????HttpServletResponse?response)? throws ?ServletException,?IOException?{??
          3. ????????response.setContentType( "text/html;charset=UTF-8" );??
          4. ????????response.setHeader( "Pragma" ,? "No-cache" );??
          5. ????????response.setHeader( "Cache-Control" ,? "no-cache" );??
          6. ????????response.setDateHeader( "Expires" ,? 0 );??
          7. ??????????????String?bitmap_data?=?request.getParameter( "bitmap_data" );??
          8. ??????????
          9. ???????? int ?width?=?commons.getRequestInt(request.getParameter( "width" ), 0 );??
          10. ???????? int ?height?=?commons.getRequestInt(request.getParameter( "height" ), 0 );??
          11. ??????????
          12. ????????BufferedImage?img?=? new ?BufferedImage(width,?height,??
          13. ????????????????BufferedImage.TYPE_INT_RGB);??
          14. ???????????????? try ?{??
          15. ??????????????
          16. ???????????? int ?w?=?width;??
          17. ???????????? int ?h?=?height;??
          18. ???????????? int []?pixels?=? new ? int [w?*?h];??
          19. ????????????String[]?m_tempPics?=?bitmap_data.split( "," );??
          20. ???????????? for ?( int ?x?=? 0 ;?x?<?w;?x++)?{??
          21. ???????????????? for ?( int ?y?=? 0 ;?y?<?h;?y++)?{??
          22. ????????????????????????????????????Long?pic_argb?=?Long.parseLong(m_tempPics[x?*?h?+?y]);??
          23. ???????????????????????????????????????? int ?a?=?( int )?(pic_argb?>>? 24 ?&? 0xFF );??
          24. ???????????????????? int ?r?=?( int )?(pic_argb?>>? 16 ?&? 0xFF );?? //右移16位?,取后8位; ??
          25. ???????????????????? int ?g?=?( int )?(pic_argb?>>? 8 ?&? 0xFF );??
          26. ???????????????????? int ?b?=?( int )?(pic_argb?&? 0xFF );??
          27. ????????????????????????????????????????pixels[y?*?w?+?x]?=? new ?Color(r,?g,?b,?a).getRGB();??
          28. ??????????????????????
          29. ????????????????}??
          30. ????????????}??
          31. ????????????img.setRGB( 0 ,? 0 ,?w,?h,?pixels,? 0 ,?w);??
          32. ????????????img.flush();??
          33. ????????????ByteArrayOutputStream?bao?=? new ?ByteArrayOutputStream();??
          34. ??????????????
          35. ????????????ImageIO.write(img,? "jpg" ,?bao);??
          36. ???????????? byte []?data?=?bao.toByteArray();??
          37. ????????????Personimage?user?=? new ?Personimage();??
          38. ????????????user.setFileContent(data);??
          39. ????????????PersonimageDAO?hm?=? new ?PersonimageDAO();??
          40. ????????????hm.save(user);??
          41. ????????????PersonrelationDAO?prm?=? new ?PersonrelationDAO();??
          42. ????????????Personrelation?pr?=?prm.findById( new ?Long(personRelationId));??
          43. ????????????pr.setPersonimageid(user.getId());??
          44. ????????????pr.setImageflag( "1" );??
          45. ????????????prm.update(pr);??
          46. ????????????str.append( "保存成功" );??
          47. ????????}? catch ?(Exception?e)?{??
          48. ????????????e.printStackTrace();??
          49. ????????????str.append( "保存失敗" );??
          50. ????????}??
          51. ????????response.setContentType( "text/xml" );??
          52. ????????response.getWriter().write(str.toString());??
          53. ????}??
          54. ??

          posted on 2011-08-05 22:32 禮物 閱讀(3024) 評(píng)論(2)  編輯  收藏

          評(píng)論

          # re: flex攝像頭拍照 java上傳到數(shù)據(jù)庫(kù) . 2012-08-31 13:48 霞之大夢(mèng)
          你好,flex的需要引什么包嗎  回復(fù)  更多評(píng)論
            

          # re: flex攝像頭拍照 java上傳到數(shù)據(jù)庫(kù) . 2014-04-13 11:04 123yedddd
          //連接WebService失敗事件
          private function __onSavePictureFault(event:FaultEvent):void
          {
          //Alert.show(event.fault.toString(),"提示",Alert.OK);
          Alert.show("連接WebService失敗。","提示",Alert.OK);
          }
          我把提示改連接WebService失敗123。 怎么沒反映啊。。還是連接WebService失敗。  回復(fù)  更多評(píng)論
            


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。

          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 万源市| 新安县| 闸北区| 衡南县| 句容市| 高清| 永顺县| 祁连县| 阜城县| 清镇市| 同德县| 河西区| 南陵县| 凤山县| 自贡市| 红河县| 裕民县| 镇坪县| 青神县| 施秉县| 罗定市| 云阳县| 揭东县| 三台县| 宁国市| 河间市| 织金县| 林州市| 清流县| 定日县| 屏南县| 乐至县| 黄山市| 泾阳县| 乡宁县| 洛阳市| 望谟县| 盈江县| 都兰县| 大港区| 龙胜|