USBcamera 之 xml java

前端之家收集整理的这篇文章主要介绍了USBcamera 之 xml java前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
wfliao@Precision-M6700:~/workspace/uvc/usbcam/res/layout$ tree
.
└── activity_main.xml

wfliao@Precision-M6700:~/workspace/uvc/usbcam/res/layout$ cat activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.uvc.usbcam.MainActivity" >




<ImageView
android:id="@+id/mimg"
android:layout_width="600dp"
android:layout_height="600dp"
android:textColor="#ff000000"
android:textSize="100sp" />


<Button
android:id="@+id/mcap"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_marginTop="200dp"
android:text="mcap" />




</RelativeLayout>



wfliao@Precision-M6700:~/workspace/uvc/usbcam/res/values$ cat strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>


<string name="app_name">usbcam</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>


</resources>




wfliao@Precision-M6700:~/workspace/uvc/usbcam/src/com/uvc/usbcam$ tree
.
├── MainActivity.java
└── USBcamera.java


0 directories,2 files


wfliao@Precision-M6700:~/workspace/uvc/usbcam/src/com/uvc/usbcam$ cat USBcamera.java
package com.uvc.usbcam;


import android.graphics.Bitmap;


public class USBcamera {
static public native int open(byte[] devname);
static public native int qbuf(int index);
static public native int streamon();
static public native int streamoff();
static public native int dqbuf(byte[] videodata);
static public native int release();
static public native int init(int width,int height,int numbuf,int ctype);
static public native int pixeltobmp(Bitmap bitmap);
static {
System.loadLibrary("USBcamera");
}
}




wfliao@Precision-M6700:~/workspace/uvc/usbcam/src/com/uvc/usbcam$ cat MainActivity.java
package com.uvc.usbcam;


import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.graphics.YuvImage;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.text.format.Time;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;


public class MainActivity extends Activity {
private ImageView mImag;
private int width = 640;
private int height = 480;
private String devname = "/dev/video0";
private byte[] mdata;
private Handler mHandler;
private int numbuf = 0;
private int index = 0;
private int ret = 0;
private int ctype = 1;//0 is zc301 1 is uvc camera
public Button mcap;
private Bitmap bitmap;
private Bitmap bmp;
private int[] rgb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
mImag = (ImageView)findViewById(R.id.mimg);
mcap = (Button)findViewById(R.id.mcap);
bmp = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
numbuf = 4;
mdata = new byte[width * height * numbuf];
rgb = new int[width * height * numbuf];
ret = USBcamera.open(devname.getBytes());
if(ret < 0)
finish();
ret = USBcamera.init(width,numbuf,ctype);
if(ret < 0)
finish();
ret = USBcamera.streamon();
if(ret < 0)
finish();
mHandler = new Handler();
new StartThread().start();
mcap.setOnClickListener(new CaptureListener());
}


final Runnable mUpdateUI = new Runnable() {


@Override
public void run() {
// TODO Auto-generated method stub
mImag.setImageBitmap(bitmap);

}
};

class StartThread extends Thread {


@Override
public void run() {
// TODO Auto-generated method stub
//super.run();
while(true) {
if(ctype == 1){
index = USBcamera.dqbuf(mdata);
if((index < 0) || (mdata == null)) {
onDestroy();
break;
}
USBcamera.pixeltobmp(bmp);
mHandler.post(mUpdateUI);
bitmap = bmp;
USBcamera.qbuf(index);
//USBcamera.yuvtorgb(mdata,rgb);
//mHandler.post(mUpdateUI);
//bitmap = Bitmap.createBitmap(rgb,width,Bitmap.Config.ARGB_8888);
//USBcamera.qbuf(index);
} else {
index = USBcamera.dqbuf(mdata);
if(index < 0) {
onDestroy();
break;
}
mHandler.post(mUpdateUI);
bitmap = BitmapFactory.decodeByteArray(mdata,width * height);
USBcamera.qbuf(index);
}
}
}
}

public static void saveMyBitmap(Bitmap mBitmap) {
Time mtime = new Time();
mtime.setToNow();
File fdir = new File(Environment.getExternalStorageDirectory().getPath() + "/DCIM/" + "/wfliao/");
if(!fdir.exists()) {
fdir.mkdir();
}
File f = new File(Environment.getExternalStorageDirectory().getPath() + "/DCIM/" + "/wfliao/" + mtime.year + mtime.month + mtime.monthDay + mtime.hour + mtime.minute +mtime.second+".png");
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
mBitmap.compress(Bitmap.CompressFormat.PNG,100,fOut);
fOut.flush();
fOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


}

class CaptureListener implements OnClickListener{


@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//new CapThread().start();
//USBcamera.streamoff();
saveMyBitmap(bitmap);
//USBcamera.streamon();
Toast.makeText(MainActivity.this,"Capture Successfully",Toast.LENGTH_SHORT).show();
}
}
/*
class CapThread extends Thread {


@Override
public void run() {
// TODO Auto-generated method stub
//super.run();
saveMyBitmap(bitmap);
Toast.makeText(MainActivity.this,Toast.LENGTH_LONG).show();
}

}
*/
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
USBcamera.release();
finish();
System.exit(0);
}


@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
USBcamera.release();
finish();
System.exit(0);
}


@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
USBcamera.release();
System.exit(0);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main,menu);
finish();
return true;
}


}


一般生成在mnt/sdcard/DCIM/camera/wfliao

原文链接:https://www.f2er.com/xml/297434.html

猜你在找的XML相关文章