• 大小: 0.17M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-26
  • 语言: Java
  • 标签: 其他  

资源简介

android使用手机摄像头.zip

资源截图

代码片段和文件信息

/*
*   @version 1.2 2012-06-29
*   @author wanghai
*/

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.EXIT_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(640480);
        panel.setLocation(0 0);
        add(panel);
        jb = new JButton(“拍照“);
        jb.setBounds(048064050);
        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();


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-10-15 07:44  CameraTest\
     文件         459  2013-09-16 14:16  CameraTest\.classpath
     文件         846  2012-06-20 21:45  CameraTest\.project
     文件        1461  2012-07-03 18:49  CameraTest\AndroidManifest.xml
     目录           0  2013-09-16 14:17  CameraTest\bin\
     文件        1461  2013-09-16 14:16  CameraTest\bin\AndroidManifest.xml
     文件       42956  2013-09-16 14:17  CameraTest\bin\CameraTest.apk
     目录           0  2013-09-16 14:16  CameraTest\bin\classes\
     目录           0  2013-09-16 14:16  CameraTest\bin\classes\org\
     目录           0  2013-09-16 14:16  CameraTest\bin\classes\org\wanghai\
     目录           0  2013-09-16 14:16  CameraTest\bin\classes\org\wanghai\CameraTest\
     文件         353  2013-09-16 14:16  CameraTest\bin\classes\org\wanghai\CameraTest\BuildConfig.class
     文件        1404  2013-09-16 14:16  CameraTest\bin\classes\org\wanghai\CameraTest\CameraTest$1.class
     文件        3167  2013-09-16 14:16  CameraTest\bin\classes\org\wanghai\CameraTest\CameraTest.class
     文件        1676  2013-09-16 14:16  CameraTest\bin\classes\org\wanghai\CameraTest\GetIP$1.class
     文件         885  2013-09-16 14:16  CameraTest\bin\classes\org\wanghai\CameraTest\GetIP$2.class
     文件        2231  2013-09-16 14:16  CameraTest\bin\classes\org\wanghai\CameraTest\GetIP.class
     文件        1540  2013-09-16 14:16  CameraTest\bin\classes\org\wanghai\CameraTest\MyThread.class
     文件         352  2013-09-16 14:17  CameraTest\bin\classes\org\wanghai\CameraTest\R$attr.class
     文件         419  2013-09-16 14:17  CameraTest\bin\classes\org\wanghai\CameraTest\R$drawable.class
     文件         524  2013-09-16 14:17  CameraTest\bin\classes\org\wanghai\CameraTest\R$id.class
     文件         463  2013-09-16 14:17  CameraTest\bin\classes\org\wanghai\CameraTest\R$layout.class
     文件         439  2013-09-16 14:17  CameraTest\bin\classes\org\wanghai\CameraTest\R$string.class
     文件         559  2013-09-16 14:17  CameraTest\bin\classes\org\wanghai\CameraTest\R.class
     文件        2088  2013-09-16 14:16  CameraTest\bin\classes\org\wanghai\CameraTest\StreamIt.class
     文件       11416  2013-09-16 14:17  CameraTest\bin\classes.dex
     目录           0  2013-09-16 14:17  CameraTest\bin\dexedLibs\
     文件         943  2013-09-16 14:17  CameraTest\bin\dexedLibs\annotations-2626851360bb9fc5460fef54dbd031a5.jar
     文件         120  2013-09-16 14:16  CameraTest\bin\jarlist.cache
     目录           0  2012-06-27 00:59  CameraTest\bin\res\
     目录           0  2012-06-27 00:59  CameraTest\bin\res\drawable-hdpi\
............此处省略38个文件信息

评论

共有 条评论