我从这里尝试了很多解决方案,但仍然没有得到整个屏幕的截图,只能生成一张SD卡。
这是我的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// Set the layout from video_main.xml
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView) findViewById(R.id.surfacelayout);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
controlInflater = LayoutInflater.from(getBaseContext());
final View viewControl = controlInflater.inflate(R.layout.imagecontrol,
null);
LayoutParams layoutParamsControl = new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
this.addContentView(viewControl, layoutParamsControl);
// Find your VideoView in your video_main.xml layout
imageview = (ImageView) findViewById(R.id.imagePoster);
Intent i = getIntent();
poster = i.getStringExtra("url_poster");
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
imgLoader.DisplayImage(poster, imageview);
System.out.println(poster);
Button buttonTakePicture = (Button) findViewById(R.id.takepicture);
buttonTakePicture.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View arg0) {
View v = viewControl.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap bitmap = v.getDrawingCache();
String dest = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
+ File.separator
+ "Camera"
+ File.separator
+ "IMG_"
+ new DateFormat()
.format("yyyyMMdd_hhmmss", new Date()) + ".jpg";
Log.d(APP_TAG, "Writing to: " + dest);
File file = new File(dest);
try {
FileOutputStream stream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, stream);
stream.flush();
stream.close();
} catch (IOException e) {
Log.e(APP_TAG, "Error taking screenshot.", e);
} finally {
v.setDrawingCacheEnabled(false);
}
}
});
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
if (previewing) {
camera.stopPreview();
previewing = false;
}
if (camera != null) {
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera = Camera.open();
camera.setDisplayOrientation(90);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}
我仍然得到黑屏,只有一个布局获得截图,而不是整个屏幕...
如何获取整个屏幕的截图?
我希望能够在没有root的情况下获得截图....
谢谢