每当我点击“拍摄截图”按钮时,它就会卡住并继续拍摄截图。
停止按钮
这个按钮的功能是停止线程并阻止代码截图。
Thread th = new Thread(new Runnable() {
@Override
public void run() {
StopThread.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
thread.interrupt();
check=false;
//textView.setText(TotalShots);
}
});
}
});
th.start(); 采取ScreenShot Button
这个按钮的功能是启动线程并开始截图。
public void screenShot(View view) throws IOException {
thread = new Thread(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (!Thread.interrupted()){
while (check)
{
captureScreenShot = (Button) findViewById(R.id.capture_screen_shot);
c = Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
name = simpleDateFormat.format(c.getTime());
mbitmap = getBitmapOFRootView(captureScreenShot);
imageView.setImageBitmap(mbitmap);
try {
createImage(mbitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
});
}
});
thread.start();
}单击以查看 应用程序UI
发布于 2016-02-27 06:41:38
不需要启动线程或类似的可以简单调用方法的按钮点击。而不是设置比位图在图像视图或任何你想要使用的位图。
易失布尔标志=真;
public void run()
{
while(flag)
{
// Do your task of calling method of screenshot
try{
Thread.Sleep(interval);
} catch(Exception e){
}
}
}单击“停止”按钮时,设置标志为false。
public Bitmap takeScreenShot(View view) {
// configuramos para que la view almacene la cache en una imagen
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
view.buildDrawingCache();
if(view.getDrawingCache() == null) return null; // Verificamos antes de que no sea null
// utilizamos esa cache, para crear el bitmap que tendra la imagen de la view actual
Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
view.destroyDrawingCache();
return snapshot;
}https://stackoverflow.com/questions/35666585
复制相似问题