文件名称:
基于android手机的远程视频监控系统
开发工具:
文件大小: 160kb
下载次数: 0
上传时间: 2012-07-13
详细说明: import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; import javax.imageio.*; import javax.swing.*; import java.net.Socket; import java.net.ServerSocket; /** *在服务器开启情况下,启动客户端,创建套接字接收图像 */ public class ImageServer { public static ServerSocket ss = null; public static void main(String args[]) throws IOException{ ss = new ServerSocket(6000); final ImageFrame frame = new ImageFrame(ss); frame.setDefaultCloseOperation(JFrame.EXI T_ON_CLOSE); frame.setVisible(true); while(true){ frame.panel.getimage(); frame.repaint(); } } } /** A frame with an image panel */ @SuppressWarnings("serial") class ImageFrame extends JFrame{ public ImagePanel panel; public JButton jb; public ImageFrame(ServerSocket ss){ // get screen dimensions Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenHeight = screenSize.height; int screenWidth = screenSize.width; // center frame in screen setTitle("ImageTest"); setLocation((screenWidth - DEFAULT_WIDTH) / 2, (screenHeight - DEFAULT_HEIGHT) / 2); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // add panel to frame this.getContentPane().setLayout(null); panel = new ImagePanel(ss); panel.setSize(640,480); panel.setLocation(0, 0); add(panel); jb = new JButton("拍照"); jb.setBounds(0,480,640,50); add(jb); saveimage saveaction = new saveimage(ss); jb.addActionListener(saveaction); } public static final int DEFAULT_WIDTH = 640; public static final int DEFAULT_HEIGHT = 560; } /** A panel that displays a tiled image */ @SuppressWarnings("serial") class ImagePanel extends JPanel { private ServerSocket ss; private Image image; private InputStream ins; public ImagePanel(ServerSocket ss) { this.ss = ss; } public void getimage() throws IOException{ Socket s = this.ss.accept(); System.out.println("连接成功!"); this.ins = s.getInputStream(); this.image = ImageIO.read(ins); this.ins.close(); } public void paintComponent(Graphics g){ super.paintComponent(g); if (image == null) return; g.drawImage(image, 0, 0, null); } } class saveimage implements ActionListener { RandomAccessFile inFile = null; byte byteBuffer[] = new byte[1024]; InputStream ins; private ServerSocket ss; public saveimage(ServerSocket ss){ this.ss = ss; } public void actionPerformed(ActionEvent event){ try { Socket s = ss.accept(); ins = s.getInputStream(); // 文件选择器以当前的目录打开 JFileChooser jfc = new JFileChooser("."); jfc.showSaveDialog(new javax.swing.JFrame()); // 获取当前的选择文件引用 File savedFile = jfc.getSelectedFile(); // 已经选择了文件 if (savedFile != null) { // 读取文件的数据,可以每次以快的方式读取数据 try { inFile = new RandomAccessFile(savedFile, "rw"); } catch (FileNotFoundException e) { e.printStackTrace(); } } int amount; while ((amount = ins.read(byteBuffer)) != -1) { inFile.write(byteBuffer, 0, amount); } inFile.close(); ins.close(); s.close(); javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), "已接保存成功", "提示!", javax.swing.JOptionPane.PLAIN_MESSAGE); } catch (IOException e) { e.printStackTrace(); } } } 这是PC机上使用类,详细请看附件... ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.